Python 'astype' not working

前端 未结 1 1949
孤城傲影
孤城傲影 2020-12-20 22:44

I am currently using Spyder from Anaconda and I am trying to convert an array containing type float to type int:

x = np.array([1, 2, 2.5])
x.astype(int)
prin         


        
相关标签:
1条回答
  • 2020-12-20 23:15

    astype returns a new array. You need to assign the result to x:

    In [298]: x = x.astype(int)
    
    In [299]: x
    Out[299]: array([1, 2, 2])
    
    0 讨论(0)
提交回复
热议问题