# In-place type conversion of a NumPy array

| | | | | | | | | | | | | |

👻 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:

Frank Innsbruck

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

Anna Wu

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!

Anna Richtgofen

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

## Shop

Learn programming in R: courses

\$FREE

Best Python online courses for 2022

\$FREE

Best laptop for Fortnite

\$399+

Best laptop for Excel

\$

Best laptop for Solidworks

\$399+

Best laptop for Roblox

\$399+

Best computer for crypto mining

\$499+

Best laptop for Sims 4

\$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries