Python-Numpy(4)常用函数

来源:互联网 发布:青岛创业软件待遇如何 编辑:程序博客网 时间:2024/06/06 09:16
import numpy as npB = np.arange(3)print B#print np.exp(B)print np.sqrt(B)

这里写图片描述

#Return the floor of the inputa = np.floor(10*np.random.random((3,4)))print a#a.shape## flatten the array#print a.ravel()#a.shape = (6, 2)# print a print a.Tprint a.resize((2,6))print a#If a dimension is given as -1 in a reshaping operation, the other dimensions are automatically calculated:#a.reshape(3,-1)

这里写图片描述

a = np.floor(10*np.random.random((2,2)))b = np.floor(10*np.random.random((2,2)))print aprint '---'print bprint '---'print np.hstack((a,b))#np.hstack((a,b))

这里写图片描述

a = np.floor(10*np.random.random((2,12)))#print a#print np.hsplit(a,3)#print np.hsplit(a,(3,4))   # Split a after the third and the fourth columna = np.floor(10*np.random.random((12,2)))print anp.vsplit(a,3)

这里写图片描述

#Simple assignments make no copy of array objects or of their data.a = np.arange(12)b = a# a and b are two names for the same ndarray objectb is ab.shape = 3,4print a.shapeprint id(a)print id(b)

这里写图片描述

#The view method creates a new array object that looks at the same data.c = a.view()c is ac.shape = 2,6#print a.shapec[0,4] = 1234a

这里写图片描述

#The copy method makes a complete copy of the array and its data.d = a.copy() d is ad[0,0] = 9999print d print a

这里写图片描述

原创粉丝点击