1.numpy基本属性
import numpy
#print(help(numpy.genfromtxt)) 查看文档
vector = numpy.array([1,2,3,4])
print(vector.shape) #矩形形状
maxtrix = numpy.array([[1,2,3,4],[11,32,43,34.0]])
print(maxtrix.shape)
print(maxtrix.dtype)
print(maxtrix)
print(type(maxtrix.shape))
(4,)
(2, 4)
float64
[[ 1. 2. 3. 4.]
[11. 32. 43. 34.]]
<class ‘tuple’>
2.向量截取
import numpy
vector = numpy.array([5,10,15,20])
print(vector[0:3])
[ 5 10 15]
matrix = numpy.array([
[5,10,15],
[20,25,30],
[35,40,45]
])
print(matrix[:,1]) #逗号前表示行,逗号后表示列,:表示所有的
print('\n')
print(matrix[:,0:2]) #打印所有的行,0-1列
print('\n')
print(matrix[1:3:,0:2]) #打印第1-2行,0-1列
[10 25 40]
[[ 5 10]
[20 25]
[35 40]]
[[20 25]
[35 40]]