简体   繁体   English

将数组拆分为多个

[英]Splitting array into multiple ones

I'd like to split my array into multiple ones: The original array looks as follows:我想将我的数组拆分为多个:原始数组如下所示:

array([[228.6311346 , 228.6311346 , 228.6311346 ],
       [418.57914851,   0.        , 228.321311  ],
       [416.83133465,   0.        , 723.25171282]])

The resulting arrays should look like this:生成的 arrays 应如下所示:

array1([228.6311346, 418.57914851, 416.83133465])
array2([228.6311346, 0., 0.])
array3([228.6311346, 228.321311, 723.25171282])
for i in range(len(array)):
    exec("array"+str(i+1)+"=array["+str(i)+"]")

It will create your variable dynamically and assign the corresponding value to it.它将动态创建您的变量并为其分配相应的值。

array = [[1],[2],[3]]
print(array0) // outputs [1] after running above code

You can also use numpy.hsplit Doc Here您也可以在此处使用 numpy.hsplit Doc

numpy.hsplit(ary, indices_or_sections)
# Split an array into multiple sub-arrays of equal size.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM