numpy基础运算1
Posted ldq1996
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了numpy基础运算1相关的知识,希望对你有一定的参考价值。
# -*- encoding:utf-8 -*- # Copyright (c) 2015 Shiye Inc. # All rights reserved. # # Author: ldq <[email protected]> # 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)
以上是关于numpy基础运算1的主要内容,如果未能解决你的问题,请参考以下文章