0

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?

3
  • One is a list and the other is a numpy array. Commented Feb 7, 2019 at 6:23
  • Check this out -> webcourses.ucf.edu/courses/1249560/pages/… Commented Feb 7, 2019 at 6:25
  • makes sense. Thanks guys! Commented Feb 7, 2019 at 6:28

1 Answer 1

1

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]]
>>> 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.