1

I am pretty new to Python, I have a list of lists, which when printed this is the following output, lets call it list1:

[['2012-09-01', '25,922'], ['2013-09-01', '41,733'], ['2014-09-01', '37,037'], ['2015-09-01', '39,510'], ['2016-09-01', '53,394']]

Then I am converting to a numpy array, just like in this thread List of lists into numpy array

and when I do:

print(numpy.array(list1))

I get the following output:

[['2012-09-01' '25,922']
 ['2013-09-01' '41,733']
 ['2014-09-01' '37,037']
 ['2015-09-01' '39,510']
 ['2016-09-01' '53,394']]

I was expecting the same output as the previous one, just like in the other thread. What stupid thing am I doing here?

When I print both types of the lists I get the following output:

<class 'list'>
<class 'numpy.ndarray'>

So its seems to be doing the right thing.

Thank you!

Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
wr_lcb_ck
  • 85
  • 2
  • 9
  • but on the other forum the output has comma dividing the elements in each list as well as separating the lists themselves – wr_lcb_ck Oct 31 '17 at 08:39
  • I want to use this array to plot in matplotlib, but with this format I dont know how to separate dates from the rest of the values – wr_lcb_ck Oct 31 '17 at 08:39
  • Okay, thanks for the explanation guys, didnt know about that. I will accept Wasi as answer as he also edited my code haha. Have a good day – wr_lcb_ck Oct 31 '17 at 08:45

2 Answers2

0

The outputs are essentially same, the only difference is python prints list in one format and array in another. But if you want to see a list-like output, you can do the following:

print(numpy.array(list1).tolist())

Though it doesn't make sense to me because you are converting the list to array and want to print in list-like format.

Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
0

That is just how numpy arrays are printed. The list is still the same eg.

print(numpy.array(list1)[0][1])

and

print(list1[0][1])

are the same.

Srinivas V
  • 93
  • 7