0

I want to convert the elements(float) into integer, but it seems not working.

#get an array from a matrix
pre_dataY = data[:, -1]
print(pre_dataY)
# float to integer
for i in range(len(pre_dataY):
    pre_dataY[i]=int(pre_dataY[i]) 
print(pre_dataY)

however, the output is :

[ 3.  2.  9. ...,  7.  5.  5.]

[ 3.  2.  9. ...,  7.  5.  5.]

I don't see why that is?

DavidG
  • 24,279
  • 14
  • 89
  • 82

2 Answers2

0

use mapping:

print map(int, pre_dataY)

Mapping create a new list with your values

Gsk
  • 2,929
  • 5
  • 22
  • 29
  • But `pre_dataY` is an array, and presumably the OP wants it to remain so. If it started as a list, the inplace change would have worked. – hpaulj Dec 14 '17 at 18:16
-1

You are missing a closing parens in the loop:

You have:

for i in range(len(pre_dataY):

It should be:

for i in range(len(pre_dataY)):
jwpfox
  • 5,124
  • 11
  • 45
  • 42