Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.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
Python 将包含numpy和数字的列表合并到一个numpy数组中_Python_Numpy - Fatal编程技术网

Python 将包含numpy和数字的列表合并到一个numpy数组中

Python 将包含numpy和数字的列表合并到一个numpy数组中,python,numpy,Python,Numpy,我有下面的清单,我想变成一个numpy。做这件事的最佳和最有效的方法是什么 [[array([1, 2, 3]), 1], [array([1, 2, 3]), 2], [array([1, 2, 3]), 4], [array([4, 4, 4]), 3]] 预期结果: [[1, 2, 3, 1], [1, 2, 3, 2], [1, 2, 3, 4], [4, 4, 4, 3]] 你可以用这个 test = [[np.array([1, 2, 3]), 1], [

我有下面的清单,我想变成一个numpy。做这件事的最佳和最有效的方法是什么

[[array([1, 2, 3]), 1], [array([1, 2, 3]), 2], [array([1, 2, 3]), 4], [array([4, 4, 4]), 3]]
预期结果:

[[1, 2, 3, 1],
 [1, 2, 3, 2],
 [1, 2, 3, 4],
 [4, 4, 4, 3]]
你可以用这个

test = [[np.array([1, 2, 3]), 1], 
        [np.array([1, 2, 3]), 2], 
        [np.array([1, 2, 3]), 4], 
        [np.array([4, 4, 4]), 3]]

np.apply_along_axis(lambda x:np.hstack((x[0],[x[1]])),axis=1,arr=test)
你可以用这个

test = [[np.array([1, 2, 3]), 1], 
        [np.array([1, 2, 3]), 2], 
        [np.array([1, 2, 3]), 4], 
        [np.array([4, 4, 4]), 3]]

np.apply_along_axis(lambda x:np.hstack((x[0],[x[1]])),axis=1,arr=test)
test = [[np.array([1, 2, 3]), 1], 
        [np.array([1, 2, 3]), 2], 
        [np.array([1, 2, 3]), 4], 
        [np.array([4, 4, 4]), 3]]

np.apply_along_axis(lambda x:np.hstack((x[0],[x[1]])),axis=1,arr=test)