码迷,mamicode.com
首页 > 编程语言 > 详细

Python numpy学习笔记(一)

时间:2014-12-18 00:02:52      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   ar   io   color   os   sp   on   

下边代码是关于numpy的一些基本用法,包括数组和矩阵操作等...

 

bubuko.com,布布扣
 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 nplg
48 print nplg.eig(a)
View Code

 

Python numpy学习笔记(一)

标签:style   blog   http   ar   io   color   os   sp   on   

原文地址:http://www.cnblogs.com/AmitX-moten/p/4170754.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!