2024-06-01 13:06:13 发布
网友
我有这样的排列:
[[[a, b], [c, d], [e, f]]]
当我对这个数组进行整形时,它会给出(2,)
(2,)
我尝试了reshape(-1)方法,但没有成功。我想把这个数组改成:
reshape(-1)
[[a, b], [c, d], [e, f]]
我怎样才能转换它?如果你能帮忙,我会很高兴的。你知道吗
您可以使用.squeeze方法。你知道吗
.squeeze
import numpy as np a = np.array([[['a', 'b'], ['c', 'd'], ['e', 'f']]]) a.squeeze()
输出:
array([['a', 'b'], ['c', 'd'], ['e', 'f']], dtype='<U1')
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)
您可以使用^{}函数。你知道吗
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
方法。你知道吗输出:
您可以使用^{} 函数。你知道吗
输出:
输出:
相关问题 更多 >
编程相关推荐