Python记录

Python使用中的一些坑和不懂的地方

Posted by AspenStars on October 18, 2019

numpy

将numpy array由浮点型转换为整型

使用astype实现

x
Out[20]: 
array([[ 5.        ,  4.        ],
       [ 4.        ,  4.33333333],
       [ 3.66666667,  4.5       ]])
 
x.astype(int)
Out[21]: 
array([[5, 4],
       [4, 4],
       [3, 4]])

list转换为np array

f = np.array(f)

不以科学计数法输出

np.set_printoptions(suppress=True)

打印数组时不省略,完整打印

np.set_printoptions(threshold=np.inf)