numpy哪个numpy函数用法可以用

posts - 12,&
comments - 0,&
trackbacks - 0
NumPy库总包含两种基本的数据类型:矩阵和数组,矩阵的使用类似Matlab,本实例用得多的是数组array。
shape()shape是numpy函数库中的方法,用于查看矩阵或者数组的维素&&&shape(array) 若矩阵有m行n列,则返回(m,n)&&&array.shape[0] 返回矩阵的行数m,参数为1的话返回列数n
tile()tile是numpy函数库中的方法,用法如下:&&&tile(A,(m,n))
将数组A作为元素构造出m行n列的数组
sum()sum()是numpy函数库中的方法&&&array.sum(axis=1)按行累加,axis=0为按列累加
argsort()argsort()是numpy中的方法,得到矩阵中每个元素的排序序号&&&A=array.argsort()
A[0]表示排序后 排在第一个的那个数在原来数组中的下标
dict.get(key,x)Python中字典的方法,get(key,x)从字典中获取key对应的value,字典中没有key的话返回0
sorted()python中的方法
min()、max()numpy中有min()、max()方法,用法如下&&&array.min(0)
返回一个数组,数组中每个数都是它所在列的所有数的最小值&&&array.min(1)
返回一个数组,数组中每个数都是它所在行的所有数的最小值
listdir('str')python的operator中的方法&&&strlist=listdir('str')
读取目录str下的所有文件名,返回一个字符串列表
split()python中的方法,切片函数&&&string.split('str')以字符str为分隔符切片,返回list
numpy中读取.csbv文件 
&&&(1)第一种方法使用loadtxt 
  # load the CSV file as a numpy matrix  dataset = np.loadtxt('./../DataAir/testdata.csv',delimiter=',')  # separate the data from the target attributes  X_test = dataset[:,0:6]  y_test = dataset[:,6]
&&&(2)第二种方法使用csv.read
  csvfile = open('./../testData/testdata.csv')
  reader1 = csv.reader(csvfile)
  mTest = 0
  vectorUnderTest = zeros((1,6))
  for lineT in reader1:
#每一行对应一个测试数据
    classNumStr = int(lineT[6])
    for k in range(6):
      lineT[k] = float(lineT[k])
#将.csv文件读取出来的字符列表转为float类型
      vectorUnderTest[:,k] = lineT[k]
#将样本加入大数据集矩阵中
&&&(3)第三种方法使用readline,readlines,read
fh = open('c:\\autoexec.bat')
fh.readlines():
line .readline() 和 .readlines() 之间的差异是后者一次读取整个文件,象 .read() 一样。 .readlines() 自动将文件内容分析成一个行的列表,该列表可以由 Python 的 for ... in ... 结构进行处理。 另一方面,.readline() 每次只读取一行,通常比 .readlines() 慢得多。仅当没有足够内存可以一次读取整个文件时,才应该使用 .readline()。
阅读(...) 评论()NumPy使用手记_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
NumPy使用手记
阅读已结束,下载本文需要
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩12页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢numpy计算矩阵的一些函数用法
我的图书馆
numpy计算矩阵的一些函数用法
import numpy as npa = np.matrix([ [1, 2, 3, 4],&& & & & & & & & & & & &[5, 5, 6, 8],& & & & & & & & & & & &[7, 9, 9, 1],& & & & & & & & & & & &[4, 6, 7, 1]&& & & & & & & & & & &])#矩阵加减法:e = a + a#ore = a - a#矩阵乘法:b = a * a & & & & & &#not matrix multiplication!#orc = np.dot(a, a) & & & & &#matrix multiplication#ord = anp.dot(a, a, d) & & & & &#matrix multiplication#转置矩阵(transpose)g = a.transpose()#orh = a.T & & & & & & &&#not matrix transpose!#逆矩阵(inverse)#The inverse of a matrix&A&is the matrix&B&such that&AB=I&where&I&is the identity matrix consisting of ones down the main diagonal. Usually&B&is denoted&B=A-1&.&#In SciPy, the matrix inverse of the Numpy array,&A, is obtained using&linalg.inv&(A)&, or using&A.I&f = np.linalg.inv(a)#orf = a ** (-1)#orf = a.I#行列式(determinant)j = np.linalg.det(a)#伴随矩阵(adjoint)#(need more test)m = np.dot(np.linalg.det(a), np.linalg.inv(a)) # A-1 = A'' / |A| &==&&&&A''=&A-1|A| &#矩阵范数(matrix norms)k = np.linalg.norms(a)
TA的最新馆藏
喜欢该文的人也喜欢

我要回帖

更多关于 numpy where函数 的文章

 

随机推荐