我有这样的数组:
[[[a, b], [c, d], [e, f]]]
当我对这个数组进行整形时,它会给出(2,)
我尝试了reshape(-1)
方法,但是没有用。我想将此数组重塑为:
[[a, b], [c, d], [e, f]]
我该如何转换?如果您有帮助,我会很高兴。
chars_list = [[["a", "b"], ["c", "d"], ["e", "f"]]]
chars_list_one = []
for element in chars_list:
for element_one in element:
chars_list_one.append(element_one)
print(chars_list_one)
您可以使用numpy.squeeze
功能。
numpy.squeeze
输出:
a = np.array([[["a", "b"], ["c", "d"], ["e", "f"]]])
print(a.shape)
print(a)
(1, 3, 2)
[[['a' 'b']
['c' 'd']
['e' 'f']]]
输出:
b = a.squeeze(0)
print(b.shape)
print(b)
您可以使用(3, 2)
[['a' 'b']
['c' 'd']
['e' 'f']]
方法。
.squeeze