Yuezhe Li
Yuezhe Li

Reputation: 1

Create empty matrix in python

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?

Upvotes: 0

Views: 3554

Answers (1)

ngub05
ngub05

Reputation: 596

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

Upvotes: 1

Related Questions