Numpy 基础运算1

时间:2021-12-30 23:07:47
# -*- encoding:utf-8 -*-
# Copyright (c) 2015 Shiye Inc.
# All rights reserved.
#
# Author: ldq <liangduanqi@shiyejinrong.com>
# Date: 2019/2/11 13:41 import numpy as np a = np.array([0, np.pi/2, np.pi, np.pi/3, np.pi/4])
b = np.arange(4, 8, 2, np.float64) #[4. 6.] b2 = b*2 #[ 8. 12.]
b3 = b + 10 #[14. 16.]
b4 = b ** 2 #[16. 36.]
b5 = b > 5 #[False True]
b6 = np.sum(b) #10.0
b7 = np.std(b) #1.0 a2 = np.sin(a) # [0.00000000e+00 1.00000000e+00 1.22464680e-16 8.66025404e-017.07106781e-01]
'''
# sin cos 的周期为2pi,sin以原点做中心对称,sin(pi/4) = 2 ** (1/2) / 2读作二分之根二
# sin(pi) = 1 , sin(pi/2) = 0
''' a3 = np.cos(a) # [ 1.00000000e+00 6.12323400e-17 -1.00000000e+00 5.00000000e-017.07106781e-01]
'''
# cos以原点的纵轴做轴对称
# cos(pi) = 0 , cos(pi/2) = 1
''' c = np.array([[1, 1], [0, 1]])
'''
[[1 1]
[0 1]]
'''
d = np.arange(4).reshape(2, 2)
'''
[[0 1]
[2 3]]
'''
d2 = np.min(d, axis=0)
'''
axis=0时以列为查找单元
[0 1]
'''
d3 = np.std(d, axis=1)
'''
axis=1时以行为查找单元
[0.5 0.5]
''' cd_dot = np.dot(c, d, out=np.array([[1,1], [0,0]]))
'''
dot矩阵相乘
[[2 4]
[2 3]]
'''
cd_dot_2 = c.dot(d)
'''
dot矩阵相乘
[[2 4]
[2 3]]
''' print(d2)
print(d3)