第一个是学习一些python的库。首先学习的是numpy的库。
import numpy
vector =numpy.array([5,10,15,20])
matrix = numpy.array([[5,10,15],[20,25,30],[35,40,45]])
print(vector)
print(matrix)
结果:
vector = numpy.array([1,2,3,4])
print(vector.shape)
matrix = numpy.array([[5,10,15],[20,25,30],[35,40,45]])
print(matrix.shape)结果:
(4,) (3, 3)shape是可以用来查询向量的基本情况,几行几列
numbers = numpy.array([1,2,3,4])
numbers.dtype
结果:
dtype('int32')dtype用来查询类型
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(matrix[:,0:2])
结果:
[10 25 40] [[ 5 10] [20 25] [35 40]]第一个位置的:表示所有的行,第二个位置表示列。
vector =numpy.array([5,10,15,20])
vector ==10
结果:
array([False, True, False, False], dtype=bool)
查找向量中有没有10,有的话返回true,没有的话返回false,后面的是类型
vector =numpy.array([5,10,15,20])
equal_to_ten = (vector ==10)
print (equa