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
numpy_array_cast_example.py
a = np.arange(50) * 1.1you 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.intinteger data type as opposed to the floating point data type of a:
numpy_zeros_like_example.py
b = np.zeros_like(a, dtype=np.int)Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow