0

So, is there a way to achieve the same thing in python as the following line in R: matrix( rep(NA, 3*5), ncol = 5 )

To be more specific, do I need to define an array before reference it in python? How is this process different from MATLAB? I tried to create an array full of 0 using np.zeros((5, 3)), but is there a way to create an empty one and simply keep adding numbers into it?

Roland
  • 127,288
  • 10
  • 191
  • 288
Yuezhe Li
  • 1
  • 1
  • 1
  • This *variable-initialization (or allocation)* is something simpy not performed in python. The matrix full of zeros is as close to empty you will get. Also the **exact** same question exists here: http://stackoverflow.com/questions/13347559/create-empty-matrix-python?rq=1 – Ma0 Nov 30 '16 at 17:49

1 Answers1

1

An array full of 0 using np.zeros((5, 3)) is the best thing you can do here because, there no such thing as "variable declaration" or "variable initialization" in Python.

See this answer: Python variable declaration

Community
  • 1
  • 1
ngub05
  • 566
  • 1
  • 8
  • 15