numpy(2)

import numpy as np
np.meshgrid(a,b)
a,b:1-D array
return coordinate system of vector a,b
np.where()
arr=np.arange(5)
arr1=np.ones(5)
con=arr>3
result=[(x if c else y)for x,c,y in zip(arr,con,arr1)]
result
Out[142]: [1.0, 1.0, 1.0, 1.0, 4]
np.where(con,arr,arr1)
Out[144]: array([ 1.,  1.,  1.,  1.,  4.])
***con: bool array,
np.cumsum(axis=None):accumulative total sum along axis
np.cumprod(axis=None):accumulative total product along axis
np.std(axis=None): standard deviation(标准差)
np.var(axis=None): variance(方差)
np.any(),np.all(),return bool array or bool
np.unique(arr)
np.in1d(arr1,arr2):element of arr1 in arr2 or not
np.intersect1d(arr,arr1): elements in arr1 and arr meanwhile
np.union(arr,arr1):the union of arr and arr1
np.setdiff1d(arr,arr1):difference set ,elemen in arr not arr1
np.setxor1d(arr,arr1): union - intersection
***save open***
np.save('filename',arr):save arr to a file by the original uncompressed binary, '.npy' as filename extension
np.load('filename.npy'):open npfile
np.savez('filename',arrs)save several arr,'npz' as the filename extension 
np.loadtxt('array_ex.txt',delimiter=',')
np.savetxt('filename',arr)

猜你喜欢

转载自blog.csdn.net/qq_41584674/article/details/78985142
今日推荐