I try to convert matlab code to python/numpy code.
I have this line:
l = single(l)
"l" is a array of arrays and as the matlab docu says "Convert to single precision".
How can I do that with numpy?
To convert a two-dimensional numpy array to single-precision, use astype
and give it the float32
argument. For example:
>>> import numpy as np
>>> a = np.array([[1.], [2.], [3.]])
>>> a
array([[ 1.],
[ 2.],
[ 3.]])
>>> a = a.astype('float32')
>>> a
array([[ 1.],
[ 2.],
[ 3.]], dtype=float32)
For more about numeric and array data types, see the documentation.