The issue is whenever I am typing the ndarray it gives the values in float. I want the output in int only.
I have tried y = int(y1) but it is showing TypeError: only size-1 arrays can be converted to Python scalars.
var = (4, 5, 6)
length = len(var)
print(length)
from numpy import empty
y1 = empty([len(var)])
y = int(y1)
print(y)
i = 0
for x in var:
print(x)
print("i = %i" % i)
y[i] = int(x)
print(y[i])
i = i + 1
print(var)
print(y)
I want the output in int type only and not in float. I have also tried inside for loop to change dtype while assigning the value each time. Is there any better way to do so?
dtypeis determined when you create the array. Assignments don't change that. Given you current level of understanding, I think creating anp.zeros(3, dtype=int)is a better idea. Ornp.array(var). Thedtypeissues are same, but it reduces confusion over the initial values of the array.