import numpy as np
a = np.array([[1,2,3],[1,2,3]])
print('a展开:\n',a.flatten())
b = np.array([1,2],dtype = int)
print('b展开:\n',b.flatten())
print('outer(a,b):\n',np.outer(a,b))
a展开:
[1 2 3 1 2 3]
b展开:
[1 2]
outer(a,b):
[[1 2]
[2 4]
[3 6]
[1 2]
[2 4]
[3 6]]
a = np.array([[1,2,3],[1,2]])
print('a展开:\n',a.flatten())
b = np.array([1,2],dtype = int)
print('b展开:\n',b.flatten())
print('outer(a,b):\n',np.outer(a,b))
a展开:
[list([1, 2, 3]) list([1, 2])]
b展开:
[1 2]
outer(a,b):
[[list([1, 2, 3]) list([1, 2, 3, 1, 2, 3])]
[list([1, 2]) list([1, 2, 1, 2])]]
分析:结果是:[[1,2,3]*1,[1,2,3]*2]
[[1,2]*1,[1,2]*2]
这样的结果是list的操作,list * N.
继续追加验证:
a = np.array([[1,2,3],[1,2]],dtype = object)
print('a展开:\n',a.flatten())
print('a[0]的类型:',type(a[0]))
b = np.array([1,2],dtype = int)
print('b展开:\n',b.flatten())
print('b[0]的类型:',type(b[0]))
c = np.outer(a,b)
print('outer(a,b)(c):\n',c)
print('c[0][1]:',c[0][1])
print('c[0][1]的类型:',type(c[0][1]))
输出结果是:
a展开:
[list([1, 2, 3]) list([1, 2])]
a[0]的类型:
b展开:
[1 2]
b[0]的类型:
outer(a,b)(c):
[[list([1, 2, 3]) list([1, 2, 3, 1, 2, 3])]
[list([1, 2]) list([1, 2, 1, 2])]]
c[0][1]: [1, 2, 3, 1, 2, 3]
c[0][1]的类型: