简体   繁体   中英

Numpy vs regular array in python

This might be a beginner question but

when I run this code

[[0.] for i in range(num_features)]

I get [[0.],[0.]]

When I run this code

np.zeros((2, 1))

I get

[[0.],

 [0.]]

As in two separate lines

Is there a significant difference between the two? If so, what's the right way to write the first bit of code?

First list is a regular list comprehension, second is a numpy array, it is TOTALLY different, here is the numpy documentation:

http://www.numpy.org/

So actually second one could be a list like the first one:

>>> np.zeros((2, 1)).tolist()
[[0.0], [0.0]]
>>> 

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