Skip to main content
`Ctrl`+`K`
scipy.constants.

# convert_temperature

scipy.constants.convert_temperature(val, old_scale, new_scale)

  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.

  `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])