我有一个数组列表,其中每个数组代表一个单元格,数组元素是坐标x,y和z,时间点和单元格id。这是它的一个部分:
cells=[ ...,
[ 264.847, 121.056, 30.868, 42. , 375. ],
[ 259.24 , 116.875, 29.973, 43. , 375. ],
[ 260.757, 118.574, 32.772, 44. , 375. ]]), array([[ 263.967, 154.089, 55.5 , 38. , 376. ],
[ 260.744, 152.924, 55.5 , 39. , 376. ],
[ 258.456, 151.373, 55.5 , 40. , 376. ],
...,
[ 259.086, 159.564, 48.521, 53. , 376. ],
[ 258.933, 159.796, 48.425, 54. , 376. ],
[ 259.621, 158.719, 51.606, 55. , 376. ]]), array([[ 291.647, 57.582, 28.178, 38. , 377. ],
[ 284.625, 59.221, 30.028, 39. , 377. ],
[ 282.915, 59.37 , 30.402, 40. , 377. ],
...,
[ 271.224, 58.534, 23.166, 42. , 377. ],
[ 270.048, 58.738, 21.749, 43. , 377. ],
[ 268.38 , 58.138, 20.606, 44. , 377. ]]), array([[ 87.83 , 222.144, 26.258, 39. , 378. ],
[ 99.779, 223.631, 24.98 , 40. , 378. ],
[ 104.107, 224.177, 23.728, 41. , 378. ],
...,
[ 127.778, 222.205, 23.123, 63. , 378. ],
[ 126.815, 222.347, 23.934, 64. , 378. ],
[ 127.824, 221.048, 25.508, 65. , 378. ]]),...]
minimumCellCoors = cells
maximumCellCoors = cells
centoEdge = radius+fcr_size
现在我想改变坐标x,y和z,所以0,1。 2.列表中的数组元素,以使它们在特定的网格中。用户给出x,y和z的间距,然后操作看起来像:
x_Coo=round(x_element/x)*x
y_Coo=round(y_element/y)*y
z_Coo=round(z_element/z)*z
所以真正的问题是,我怎么能对数组中的所有元素(或者在这种情况下是列表中数组中的前三个元素)进行操作?
修改
如果我使用list comprehension到列表中,如:
[np.round((cellID[:,0]-(centoEdge+1))/x)*x for cellID in minimumCellCoors]
[np.round((cellID[:,1]-(centoEdge+1))/y)*y for cellID in minimumCellCoors]
[np.round((cellID[:,2]-(centoEdge+1))/z)*z for cellID in minimumCellCoors]
[np.round((cellID[:,0]+(centoEdge+1))/x)*x for cellID in maximumCellCoors]
[np.round((cellID[:,1]+(centoEdge+1))/x)*y for cellID in maximumCellCoors]
[np.round((cellID[:,2]+(centoEdge+1))/x)*z for cellID in maximumCellCoors]
我怎样才能将单个数组列表再次融合到一个数组中?
祝你好运!
答案 0 :(得分:1)
首先,您需要将列表转换为numpy数组。在第一个位置创建一个numpy数组而不是列表更合适。然后你可以利用numpy的矢量化操作支持:
以下是一个例子:
In [53]: arr[:,:,:3] = np.round(arr[:,:,:3]/5)*[4, 5, 6]
请注意,您还可以使用相同长度的数组和标量执行操作:
例如,您也可以执行以下操作:
mss