NumPy Exercises

NumPy: Convert numpy dtypes to native python types

NumPy: Basic Exercise-41 with Solution

Write a NumPy program to convert numpy dtypes to native python types.

Sample Solution :

Python Code :

import numpy as np
print("numpy.float32 to python float")
x = np.float32(0)
pyval = x.item()

Sample Output:

numpy.float32 to python float
<class 'numpy.float32'>
<class 'float'>

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to compute the x and y coordinates for points on a sine curve and plot the points using matplotlib.
Next: NumPy: Array Object Exercises Home

What is the difficulty level of this exercise?