Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
要列出的nparray的Python列表_Python_List - Fatal编程技术网

要列出的nparray的Python列表

要列出的nparray的Python列表,python,list,Python,List,我已经搜索了几个小时,找到了一种将nparray列表转换为列表的方法。 我使用的函数的输出是: [array([[[ 65, 172]], [[ 64, 173]], ... , [[ 65, 173]]]), array([[[ 70, 144]], [[ 70, 145]], ... , [[ 71, 144]]]), array([[[ 71, 132]] ,[[2, 1]]])] 当我选择列表为[0]的第一个项目时,我得到: [[[ 65 172]] [[64 173]] ... [

我已经搜索了几个小时,找到了一种将nparray列表转换为列表的方法。 我使用的函数的输出是:

[array([[[ 65, 172]], [[ 64, 173]], ... , [[ 65, 173]]]),
array([[[ 70, 144]], [[ 70, 145]], ... , [[ 71, 144]]]), 
array([[[ 71, 132]] ,[[2, 1]]])]
当我选择列表为[0]的第一个项目时,我得到:

[[[ 65 172]] [[64 173]] ... [[65 173]]]
所以我现在想要得到的是这样的东西,所有元素都在一个列表中,但不能用comas或分号分隔:

[[[ 65 172]] [[64 173]] ... [[ 71 132]] [[2 1]]]
python中是否有任何东西可以将我的nparray列表转换为我想要获得的输出列表,或者将列表中的每一项串联/连接为一个


提前感谢您的帮助。

您应该忽略输出中的逗号。它们只是文本输出,而不是数据的一部分。相反,开始考虑阵列形状。根据前面的回答,您有一个数组列表,每个数组都有形状

[(19, 1, 2), (9, 1, 2), (1, 1, 2), (14, 1, 2), (12, 1, 2), (760, 1, 2), (632, 1, 2)]
要创建一个大数组,在其中保留维度
1
2
,只需沿数组的轴
0
附加数组,只需使用
numpy.concatenate
。预期的输出形状应为

(x, 1, 2)
其中,
x
是所有第一维度形状的总和:

import numpy

# Random data, shapes taken from your answer earlier
data = [numpy.random.rand(19, 1, 2), numpy.random.rand(9, 1, 2), numpy.random.rand(1, 1, 2), numpy.random.rand(14, 1, 2), numpy.random.rand(12, 1, 2), numpy.random.rand(760, 1, 2), numpy.random.rand(632, 1, 2)]

# Concatenate along axis 0. All other dimension must be equal in shape!
out = numpy.concatenate(data, axis=0)

print out.shape  # (1447, 1, 2)

你能打印所有阵列的形状吗<代码>打印[数据中x的x.shape]。你能详细说明一下你想要的输出形状是什么吗?@NilsWerner我是python新手,我不知道如何区分数据类型。当我对得到的输出使用shape时,我得到[(19,1,2),(9,1,2),(1,1,2),(14,1,2),(12,1,2),(760,1,2),(632,1,2)]。我可以将列表添加到一起,但每个项目之间会出现一个昏迷:[[65172]]、[[64173]]、…、[[65174]]、[[65173]]。我想要的是没有comas的相同输出。另外,如果我在函数中使用数据[0],我想使用它,但在我刚才展示的函数中,它表示“不是一个numpy数组,也不是一个标量”。@NilsWerner这里有我想要的输出形状(我从项数据[0]中获取):[(1,2),(1,2),…,(1,2)]谢谢您的回复,它工作得很好!我没有执行第一条指令,因此连接不起作用。