numpy中的==代表比较两个相同尺寸array对应位置上的元素是否相等,相等则返回True(1),不相等则返回Falss(0),最终的结果为与两个array尺寸相同的布尔类型array,实例如下:
import numpy as np
x1 = np.random.randint(0,5,(3,4))
x2 = np.random.randint(0,5,(3,4))
print(x1)
print(x2)
print(x1==x2)
输出结果为:
[[0 1 1 4]
[2 0 3 1]
[2 2 0 3]]
[[3 1 2 2]
[1 2 1 1]
[0 1 3 1]]
[[False True False False]
[False False False True]
[False False False False]]
np.random.randint(0,5,(3,4))代表生成的尺寸为[3,4],数值范围为0-5(不包括5)的 array