[Numpy-discussion] specifying array sizes in random vs. ones, zeros, etc
Robert Kern
robert.kern@gmail....
Thu Nov 11 09:45:09 CST 2010
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 2-by-3 array, and then a "ones" 2-by-3 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.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion
mailing list