【小睿的ML之路】Numpy基本操作篇
import numpy
vector = numpy.array(["1","2","3"])
print(vector)
print(vector.dtype)
vector = vector.astype(float) #类型转换
print(vector)
print(vector.dtype)
['1' '2' '3']
<U1
[1. 2. 3.]
float64
print(vector.min())
1.0
matrix = numpy.array([
[5,10,15],
[20,25,30],
[35,40,45]
])
matrix.sum(axis=1) # 按行求和
array([ 30, 75, 120])
matrix = numpy.array([
[5,10,15],
[20,25,30],
[35,40,45]
])
matrix.sum(axis=0) # 按列求和
array([60, 75, 90])