该函数可以方便地判断数组element中的元素是否属于test_elements,以上述问题为例,其程序如下:
a = np.array([
[1,2,3],
[4,5,6],
[7,8,9]
])
b = [3,4,5,6,7]
print(np.isin(a, b))
[Out]:
[[False False True]
[ True True True]
[ True False False]]
np.hstack,np.vstack
np.hstack():水平方向排列数组,行数不变,列数增加。一般用于三维以下的数组。
np.vstack():垂直方向排列数组,列数不变,行数增加。一般用于三维以下的数组。
import numpy as np
a = np.arange(6).reshape(2, 3) # a.shape=(2,3)
b = np.arange(6).reshape(2, 3) # b.shape=(2,3)
c = np.hstack((a, b)) # c.shape=(2,6)
d = np.vstack((a, b)) # d.shape=(4,3)
print('a = ', a)
print('b = ', b)
print('c = ', c)
print('d = ', d)
torch.multinomial()理解
参考文献:
https://blog.csdn.net/qq_23936173/article/details/86625319
https://blog.csdn.net/qq_42191914/article/details/105600141
https://blog.csdn.net/weixin_42018112/article/details/91351771



