numpy.shape
>>> import numpy as np >>> a = np.array([1, 2, 3, 4]) >>> a.shape (4,) >>> a.shape[0] 4 >>> c = np.array([[1, 2, 3, 4],[4, 5, 6, 7], [7, 8, 9, 10]]) >>> c.shape (3, 4) >>> c.shape[0] 3 >>> c.shape[1] 4
range
>>> range(1,5) #代表从1到5(不包含5) [1, 2, 3, 4] >>> range(1,5,2) #代表从1到5,间隔2(不包含5) [1, 3] >>> range(5) #代表从0到5(不包含5) [0, 1, 2, 3, 4]
numpy.sum() 求和
>>> a array([[6, 7, 1, 6], [1, 0, 2, 3], [7, 8, 2, 1]]) >>> np.sum(a) 44 >>> np.sum(a,axis=0) array([14, 15, 5, 10]) >>> np.sum(a,axis=1) array([20, 6, 18]) >>> np.sum(a,axis=-1)
numpy.mean() 均值
>>> a array([[6, 7, 1, 6], [1, 0, 2, 3], [7, 8, 2, 1]]) >>> np.mean(a) 3.6666666666666665 >>> np.mean(a,axis=0) array([ 4.66666667, 5. , 1.66666667, 3.33333333])
numpy.var() 方差
>>> np.var(a) 7.7222222222222223 >>> np.var(a,axis=0) array([ 6.88888889, 12.66666667, 0.22222222, 4.22222222])
numpy.std() 标准差
>>> np.std(a,axis=0) array([ 2.62466929, 3.55902608, 0.47140452, 2.05480467])
- numpy.max() 最大值
- numpy.min() 最小值
- numpy.argmax() 最大值的下标
- numpy.argmin() 最小值的下标
numpy.sort() 排序
>>> a array([[6, 7, 1, 6], [1, 0, 2, 3], [7, 8, 2, 1]]) >>> a.sort() >>> a array([[1, 6, 6, 7], [0, 1, 2, 3], [1, 2, 7, 8]]) >>> np.sort(a,axis=0) array([[0, 1, 2, 3], [1, 2, 6, 7], [1, 6, 7, 8]])
numpy.argsort() 排序后的数据原来位置的下标
>>> np.argsort(a,axis=0) array([[1, 1, 1, 1], [0, 2, 0, 0], [2, 0, 2, 2]])
pickle.load(file) Read a string from the open file object file and interpret it as a pickle data stream, reconstructing and returning the original object hierarchy
Welcome To PyCrust 0.7.2 - The Flakiest Python Shell Sponsored by Orbtech - Your source for Python programming expertise. Python 2.2.1 (#1, Aug 27 2002, 10:22:32) [GCC 3.2 (Mandrake Linux 9.0 3.2-1mdk)] on linux-i386 Type "copyright", "credits" or "license" for more information. >>> import cPickle as pickle >>> t1 = ('this is a string', 42, [1, 2, 3], None) >>> t1 ('this is a string', 42, [1, 2, 3], None) >>> p1 = pickle.dumps(t1) >>> p1 "(S'this is a string'\nI42\n(lp1\nI1\naI2\naI3\naNtp2\n." >>> print p1 (S'this is a string' I42 (lp1 I1 aI2 aI3 aNtp2 . >>> t2 = pickle.loads(p1) >>> t2 ('this is a string', 42, [1, 2, 3], None) >>> p2 = pickle.dumps(t1, True) >>> p2 '(U\x10this is a stringK*]q\x01(K\x01K\x02K\x03eNtq\x02.' >>> t3 = pickle.loads(p2) >>> t3 ('this is a string', 42, [1, 2, 3], None)
- 14.
python使用
最新推荐文章于 2024-08-21 22:35:36 发布