How to create NumPy array that is exactly as long as another array but has a different data type
Want to have the same data type as a
as well as the same size? SeeHow to create NumPy array that is exactly as long as another array
If you have a numpy array such as
a = np.arange(50) * 1.1
you can use the following code to create an array b
that has the same dimensions, i.e. the same size as a
, but uses the np.int
integer data type as opposed to the floating point data type of a
:
b = np.zeros_like(a, dtype=np.int)