numpy_3rd 布尔运算/乘积点积

本系列来自B站up主莫烦的视频 https://www.bilibili.com/video/BV1Ex411L7oT?p=7


import numpy as np

"""
1. 对矩阵进行布尔运算生成的是 相同shape的布尔值
b = np.arange(4) print(b<3)
[ True True True False]

2. 矩阵的三角函数,都是作用在矩阵的每个元素中,类似 map(sin(),array)
a = np.array(([10,20,30,40]))
np.tan(a)
[ 0.64836083 2.23716094 -6.4053312 -1.11721493]


d = np.array([[1,1],[0,1]])
e = np.arange(4).reshape((2,2))
3. 两个矩阵的乘积,是对应项相乘
f = d*e
[[0 1]
[0 3]]
4. 两个矩阵的内积dot_product 是对应向量相乘
res = np.dot(d,e)
res = d.dot(e)
[[2 4]
[2 3]]
5. array的一些统计学方法
np.sum(h)
np.max(h)
np.min(h)
6. 其中对参数axis的运用
# 每一行的求和
np.sum(h,axis = 0)
# 每一列的求和
np.sum(h,axis = 1)


"""
a = np.array(([10,20,30,40]))
b = np.arange(4)

print(b<3)
print(b==3)
c = np.tan(a)
print(c)
print(a-b)
print(b**2)

d = np.array([[1,1],[0,1]])
e = np.arange(4).reshape((2,2))
print(d,'\n',e)

# 对应项相乘
f = d*e
# 矩阵乘法
g = np.dot(d,e)
g_1 = d.dot(e)
print(f,'\n',g)

h = np.random.random((2,4))
print(h)

np.sum(h)
# 每一行的求和
np.sum(h,axis = 0)
# 每一列的求和
np.sum(h,axis = 1)
np.max(h)
np.min(h)
posted @ 2020-05-15 13:14  ChevisZhang  阅读(665)  评论(0编辑  收藏  举报