1

what is the method to convert an array of arbitrary shape to a 1D array in python? I'm looking for something like this

my_array = numpy.array( [4,[5,6],[7,8,9]] )
my_array_flattened = [4,5,6,7,8,9]

numpy.flatten('F') is not working

brownser
  • 545
  • 7
  • 25
  • Are you sure, you want a ragged array in the first place? This is not supported directly in recent numpy versions. Only as array of lists. – Dima Chubarov Aug 18 '21 at 08:59

1 Answers1

1

Try np.hstack:

>>> np.hstack(my_array)
array([4, 5, 6, 7, 8, 9])
>>> 
U13-Forward
  • 69,221
  • 14
  • 89
  • 114