specifying array sizes in random vs. ones, zeros, etc
I'm a hopeful Matlab refugee trying to understand the numpy way. Perhaps someone can explain why some numpy functions require shape specifications in different ways. For example, below I create a random 2by3 array, and then a "ones" 2by3 array:
A = numpy.random.randn(2,3) B = numpy.ones((2,3))
The first call takes 2 arguments; the 2nd takes a single tuple argument. This strikes me as inconsistent, but probably I'm not grokking some numpy subleties. Can someone please explain?
On Thu, Nov 11, 2010 at 08:44, Michael Friedlander mpf@cs.ubc.ca wrote:
I'm a hopeful Matlab refugee trying to understand the numpy way. Perhaps someone can explain why some numpy functions require shape specifications in different ways. For example, below I create a random 2by3 array, and then a "ones" 2by3 array:
A = numpy.random.randn(2,3) B = numpy.ones((2,3))
The first call takes 2 arguments; the 2nd takes a single tuple argument. This strikes me as inconsistent, but probably I'm not grokking some numpy subleties. Can someone please explain?
rand() and randn() were added as conveniences for people who were used to the MATLAB functions. numpy.random.random_sample((2,3)) and numpy.random.standard_normal((2,3)) are the preferred, more consistent functions to use. Ignore rand() and randn() if you like.
participants (2)

Michael Friedlander

Robert Kern