首页 > 代码库 > Python numpy学习笔记(一)
Python numpy学习笔记(一)
下边代码是关于numpy的一些基本用法,包括数组和矩阵操作等...
1 import numpy as np 2 print "<== print version ==>" 3 print np.version.version 4 print "<== 1-dimensional array ==>" 5 print np.array([1, 2, 3, 4, 5]) 6 print "<== 2-dimentional array ==>" 7 print np.array([[1,2],[3,4]]) 8 print "<== int32,int16,etc. ==>" 9 print np.array((1, 2, 3, 4), dtype = np.float64)10 print "<== get a 3*5 array ==>"11 print np.arange(15).reshape(3, 5)12 print "<== generate 4 data from 1 to 5 ==>"13 print np.linspace(1, 5, 4)14 print "<== like what in matlab ==>"15 print np.zeros((2, 5))#16 print ‘\n‘17 print np.ones((2,5))18 print ‘\n‘19 print np.eye(3)20 21 a = np.eye(4)22 print "<== sum ==>"23 a.sum()24 a.sum(axis=0)25 print "<== min and max ==>"26 a.min()27 a.max()28 np.sin(a)29 np.floor(a)30 np.exp(a)31 np.dot(a, a)32 33 a = np.ones((2,2))34 b = np.eye(2)35 print "<== visit array ==>"36 print a[0, 0]37 print "<== merge: shallow copy: learn from v and h ==>"38 print np.vstack((a,b))39 print np.hstack((a,b))40 print "<== deep copy ==>"41 c = a.copy()42 print "<== transpose ==>"43 print c.transpose()44 print "<== trace ==>"45 print c.trace()46 print "<== more matrix operations in linalg ==>"47 import numpy.linalg as nplg48 print nplg.eig(a)
Python numpy学习笔记(一)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。