Suppose the following:
import numpy as np
a = np.array ( [1.1, 2.2, 3.3] )
How to convert this array to int
without having to iterate each element or using another array?
Why to:
b = int(a)
It gives an error because it is only possible to convert an array of length 1 to int
. So I try:
for i in a:
int(i)
# ou
# i = int(i)
does not resolve, because a
, after the loop remains with elements in float.
I would then have to use one more array to do this and iterate over this array:
b = np.zeros( a.shape )
for i in xrange(0, len(a))
b[i] = int(a[i])
Returns an array with the integers, yes, but still of type float
, note the point ...
print b
[1., 2., 3.]
How to convert to int?