Home > database >  Turning a Multi-Dimensional Array Into A Linear One Dimensional Array
Turning a Multi-Dimensional Array Into A Linear One Dimensional Array

Time:09-01

I am a bit new to python and I have a large list of data whose shape is as such:

print(mydata.shape)
>>> (487, 24, 12 , 13)

One index of this array itself looks like this:

[4.22617843e-11 5.30694273e-11 3.73693923e-11 2.09353628e-11
    2.42581129e-11 3.87492538e-11 2.34626762e-11 1.87155829e-11
    2.99512706e-11 3.32095254e-11 4.91165476e-11 9.57019117e-11
    7.86496424e-11]]]]

I am trying to take all the elements from this multi-dimensional array and put it into a one-dimensional one so I can graph it. I would appreciate any help. Thank you.

CodePudding user response:

mydata.ravel()

Will make a new array, flattened to shape:

(487*24*12*13,)

or...

(1823328,)

CodePudding user response:

You can do this by using flatten()

mydata.flatten(order='C')

And order types depend on the following: order: The order in which items from the NumPy array will be read.

  • ‘C’: Read items from array row wise i.e. using C-like index order.
  • ‘F’: Read items from array column wise i.e. using Fortran-like index order.
  • ‘A’: Read items from an array based on the memory order of items
  • Related