0

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:

array1([228.6311346, 418.57914851, 416.83133465])
array2([228.6311346, 0., 0.])
array3([228.6311346, 228.321311, 723.25171282])
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Marco
  • 25
  • 6

1 Answers1

1
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(ary, indices_or_sections)
# Split an array into multiple sub-arrays of equal size.
Saket Anand
  • 45
  • 1
  • 10
  • `split`/`hsplit` is the correct answer. `exec` is a bad idea (despite the fact that it more closely matches OP's desired output). – 0x5453 Jun 08 '21 at 19:42