array的相关运算符介绍

array的相关运算符介绍,第1张

一、+ - * / 运算符
import numpy as np

a = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
b = np.array([[1, 2, 9, 10], [5, 6, 7, 8]])
c1 = a + b 				#plus
print(c1)
c2 = a - b 				#minus
print(c2)
c3 = a * b 				#multiply
print(c3)
c4 = a / b 				#divide
print(c4)

>>>
[[ 2  4 12 14]
 [10 12 14 16]]


[[ 0  0 -6 -6]
 [ 0  0  0  0]]


[[ 1  4 27 40]
 [25 36 49 64]]


[[1.         1.         0.33333333 0.4       ]
 [1.         1.         1.         1.        ]]
二、> < == 运算符
import numpy as np

a = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
b = np.array([[1, 2, 9, 10], [5, 6, 7, 8]])

c5 = a == b             #return the boolean value of a==b
print(c5)
c6 = a > b              #return the boolean value of a>b
print(c6)
c7 = a < b 				#return the boolean value of a>>
[[ True  True False False]
 [ True  True  True  True]]


[[False False False False]
 [False False False False]]


[[False False  True  True]
 [False False False False]]
三、** sin() cos() tan() 运算符
import numpy as np

a = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
b = np.array([[1, 2, 9, 10], [5, 6, 7, 8]])

c1 = a ** b				#power
print(c1)
c2 = np.sin(a)			#sin
print(c2)
c3 = np.cos(a)			#cos
print(c3)
c4 = np.tan(a)			#sin
print(c4)

>>>
[[       1        4    19683  1048576]
 [    3125    46656   823543 16777216]]


[[ 0.84147098  0.90929743  0.14112001 -0.7568025 ]
 [-0.95892427 -0.2794155   0.6569866   0.98935825]]


[[ 0.54030231 -0.41614684 -0.9899925  -0.65364362]
 [ 0.28366219  0.96017029  0.75390225 -0.14550003]]


[[ 1.55740772 -2.18503986 -0.14254654  1.15782128]
 [-3.38051501 -0.29100619  0.87144798 -6.79971146]]

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/737103.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-28
下一篇 2022-04-28

发表评论

登录后才能评论

评论列表(0条)