0

I'm working with some climate data at the moment, but it comes in a weird shape. The arrays look the following:

       ([[0.02115021]],

        [[0.03046454]],

        [[0.05636626]],

        [[0.08100581]],

        [[0.1113209 ]],

        [[0.11042633]],

        [[0.12332429]],

        [[0.1256145 ]],

        [[0.13792552]],

        [[0.11826107]],

        [[0.05710823]]],
  mask=False,
  fill_value=1e+20,
  dtype=float32)

But I want just a simple numpy array looking like ([1,2,3,4,5,6,7]), since this is a time series. I tried to convert it with np.asarray(data), but the double brackets around the values are still there, what makes working with the data kinda impossible. Does anybody has an idea how to get rid of them?

Thanks a lot.

Marek
  • 160
  • 1
  • 2
  • 17

2 Answers2

4

Flatten method of numpy array can be used to convent n-d array into 1d array.

a = np.array([[1,2],[3,4]])
a.flatten()
# output: array([1, 2, 3, 4])

More information at https://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html

Keval Dave
  • 2,777
  • 1
  • 13
  • 16
  • Thank you, I expected it to be a super simple solution, but my googling skills were off. :) – Marek Feb 04 '20 at 10:36
0

This is easy to use and is called list comprehension:

[wi[0][0] for wi in data]
Srinivas P
  • 112
  • 1
  • 6