w3resource logo
Python Exercises

Python NumPy: Convert the values of Centigrade degrees into Fahrenheit degrees

Python NumPy: Array Object Exercise-14 with Solution

Write a Python program to convert the values of Centigrade degrees into Fahrenheit degrees. Centigrade values are stored into a NumPy array.
Sample Array [0, 12, 45.21 ,34, 99.91]

Sample Solution:-

Python Code:

import numpy as np
fvalues = [0, 12, 45.21, 34, 99.91]
F = np.array(fvalues)
print("Values in Fahrenheit degrees:")
print(F)
print("Values in  Centigrade degrees:") 
print(5*F/9 - 5*32/9)

Sample Output:

Values in Fahrenheit degrees:                                           
[  0.    12.    45.21  34.    99.91]                                    
Values in  Centigrade degrees:                                          
[-17.77777778 -11.11111111   7.33888889   1.11111111  37.72777778]

Python Code Editor:

import numpy as np
fvalues = [0, 12, 45.21, 34, 99.91]
F = np.array(fvalues)
print("Values in Fahrenheit degrees:")
print(F)
print("Values in  Centigrade degrees:") 
print(5*F/9 - 5*32/9)

Improve this sample solution and post your code through Disqus