scipy.constants.

convert_temperature#

scipy.constants.convert_temperature(val, old_scale, new_scale)[source]#

Convert from a temperature scale to another one among Celsius, Kelvin, Fahrenheit, and Rankine scales.

Parameters:
valarray_like

Value(s) of the temperature(s) to be converted expressed in the original scale.

old_scalestr

Specifies as a string the original scale from which the temperature value(s) will be converted. Supported scales are Celsius (β€˜Celsius’, β€˜celsius’, β€˜C’ or β€˜c’), Kelvin (β€˜Kelvin’, β€˜kelvin’, β€˜K’, β€˜k’), Fahrenheit (β€˜Fahrenheit’, β€˜fahrenheit’, β€˜F’ or β€˜f’), and Rankine (β€˜Rankine’, β€˜rankine’, β€˜R’, β€˜r’).

new_scalestr

Specifies as a string the new scale to which the temperature value(s) will be converted. Supported scales are Celsius (β€˜Celsius’, β€˜celsius’, β€˜C’ or β€˜c’), Kelvin (β€˜Kelvin’, β€˜kelvin’, β€˜K’, β€˜k’), Fahrenheit (β€˜Fahrenheit’, β€˜fahrenheit’, β€˜F’ or β€˜f’), and Rankine (β€˜Rankine’, β€˜rankine’, β€˜R’, β€˜r’).

Returns:
resfloat or array of floats

Value(s) of the converted temperature(s) expressed in the new scale.

Notes

Added in version 0.18.0.

Array API Standard Support

convert_temperature has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

Library

CPU

GPU

NumPy

βœ…

n/a

CuPy

n/a

βœ…

PyTorch

βœ…

βœ…

JAX

βœ…

βœ…

Dask

βœ…

n/a

See Support for the array API standard for more information.

Examples

>>> from scipy.constants import convert_temperature
>>> import numpy as np
>>> convert_temperature(np.array([-40, 40]), 'Celsius', 'Kelvin')
array([ 233.15,  313.15])