简体   繁体   中英

list of lists into numpy array - wrong output

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM