convert numpy string array into int array

numpy, python

Solution

import numpy as np

a = np.array([['-0.99', '', '0.56', '0.56', '-2.02', '-0.96']])
a[a == ''] = 0.0
a = a.astype(np.float)

Result is:

[[-0.99  0.    0.56  0.56 -2.02 -0.96]]

Your values are floats, not integers. It is not clear if you want a list of lists or a numpy array as your end result. You can easily get a list of lists like this:

a = a.tolist()

Result:

[[-0.99, 0.0, 0.56, 0.56, -2.02, -0.96]]

Problem

I have a numpy.ndarray ``` a = [['-0.99' '' '0.56' ..., '0.56' '-2.02' '-0.96']] ``` how to convert it to int? output : ``` a = [[-0.99 0.0 0.56 ..., 0.56 -2.02 -0.96]] ``` I want 0.0 in place of blank ''

Original source

Related problems