简体   繁体   English

列表列表进入numpy数组-错误的输出

[英]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: 我对Python很陌生,我有一个列表列表,在打印时,这是以下输出,可将其称为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 然后我将转换为numpy数组,就像在该线程中将列表列表转换为numpy数组一样

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. 输出本质上是相同的,唯一的区别是python打印列表以一种格式,数组以另一种格式。 But if you want to see a list -like output, you can do the following: 但是,如果要查看类似list的输出,可以执行以下操作:

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. 尽管对我来说这没有意义,因为您正在将列表转换为数组,并希望以类似list的格式进行打印。

That is just how numpy arrays are printed. 那就是numpy数组的打印方式。 The list is still the same eg. 该列表仍然相同,例如。

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

and

print(list1[0][1])

are the same. 是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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