👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
Given a NumPy array of int32
, how do I convert it to float32
in place? So basically, I would like to do
a = a.astype(numpy.float32)
without copying the array. It is big.
The reason for doing this is that I have two algorithms for the computation of a
. One of them returns an array of int32
, the other returns an array of float32
(and this is inherent to the two different algorithms). All further computations assume that a
is an array of float32
.
Currently I do the conversion in a C function called via ctypes
. Is there a way to do this in Python?
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from In-place type conversion of a NumPy array, check other array Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano In-place type conversion of a NumPy array
- Deutsch In-place type conversion of a NumPy array
- Français In-place type conversion of a NumPy array
- Español In-place type conversion of a NumPy array
- Türk In-place type conversion of a NumPy array
- Русский In-place type conversion of a NumPy array
- Português In-place type conversion of a NumPy array
- Polski In-place type conversion of a NumPy array
- Nederlandse In-place type conversion of a NumPy array
- 中文 In-place type conversion of a NumPy array
- 한국어 In-place type conversion of a NumPy array
- 日本語 In-place type conversion of a NumPy array
- हिन्दी In-place type conversion of a NumPy array
Berlin | 2023-01-31
io Python module is always a bit confusing 😭 In-place type conversion of a NumPy array is not the only problem I encountered. Will use it in my bachelor thesis
Warsaw | 2023-01-31
Simply put and clear. Thank you for sharing. In-place type conversion of a NumPy array and other issues with ast Python module was always my weak point 😁. Checked yesterday, it works!
California | 2023-01-31
I was preparing for my coding interview, thanks for clarifying this - In-place type conversion of a NumPy array in Python is not the simplest one. Will get back tomorrow with feedback