0

Let's assume I have an 2D array named 'example'

example = np.array([[14],[34],[234],[17],[80],[4563],[1456],[2345],[3456],[34565]])

What I want to do here is to transform the array to a list that looks like:

[14, 34, 234, 17, 80, 4563, 1456, 2345, 3456, 34565]

How can I get the above list from the array?

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
Hari Jinn
  • 29
  • 4

1 Answers1

2

I would do it this way, as it seems to be the most natural expression of what you're trying to do:

example.flatten().tolist()
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Probably, the OP should stick to an array. Who knows. But they are certainly confused about what is in their array. If it *were* an array of lists, this wouldn't actually work. – juanpa.arrivillaga Jan 31 '21 at 07:10