[Matrix-SIG] bug in array constructor for type 'O'

Emmanuel Viennet emmanuel.viennet@lipn.univ-paris13.fr
Mon, 20 Dec 1999 13:49:13 +0100


 The 'O' typecode is seldom used and obviously needs some
debugging...
 While you're at it, the display (repr) code is also wrong:

>>> b
array([None , floor , bar , ba ],'O')

is incorrect: we should get

 array([None , 'floor' , 'bar' , 'ba' ],'O')


Emmanuel
-- 
Emmanuel Viennet: <emmanuel.viennet@lipn.univ-paris13.fr>
http://www-lipn.univ-paris13.fr/~viennet/


Return-Path: <owner-matrix-sig@python.org>
Delivered-To: matrix-sig@dinsdale.python.org
Received: from python.org (parrot.python.org [132.151.1.90])
	by dinsdale.python.org (Postfix) with ESMTP id 350081CD16
	for <matrix-sig@dinsdale.python.org>; Sat, 18 Dec 1999 18:06:50 -0500 (EST)
Received: from web3105.mail.yahoo.com (web3105.mail.yahoo.com [204.71.202.190])
	by python.org (8.9.1a/8.9.1) with SMTP id SAA14480
	for <matrix-sig@python.org>; Sat, 18 Dec 1999 18:06:47 -0500 (EST)
Message-ID: <19991218230702.25490.qmail@web3105.mail.yahoo.com>
Received: from [15.255.176.47] by web3105.mail.yahoo.com; Sat, 18 Dec 1999 15:07:02 PST
Date: Sat, 18 Dec 1999 15:07:02 -0800 (PST)
From: Lee Barford <lee_barford@yahoo.com>
To: Python Matrix Sig <matrix-sig@python.org>,
	LLNL Distribution Support <support@icf.llnl.gov>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="0-1804289383-945558422=:25420"
Subject: [Matrix-SIG] Additions to RandomArray
Sender: matrix-sig-admin@python.org
Errors-To: matrix-sig-admin@python.org
X-BeenThere: matrix-sig@python.org
X-Mailman-Version: 1.2 (experimental)
Precedence: bulk
List-Id: SIG for Built-in Matrix Types in Python <matrix-sig.python.org>

--0-1804289383-945558422=:25420
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

The attachments to my previous message didn't make it.
Please forgive this second attempt. If this doesn't
work, I'll look for some other way of submitting them.

--Lee Barford

__________________________________________________
Do You Yahoo!?
Thousands of Stores.  Millions of Products.  All in one place.
Yahoo! Shopping: http://shopping.yahoo.com
--0-1804289383-945558422=:25420
Content-Type: text/html; name="RandomArray-additions.html"
Content-Description: RandomArray-additions.html
Content-Disposition: inline; filename="RandomArray-additions.html"

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="GENERATOR" content="Mozilla/4.6 [en] (X11; I; Linux 2.2.10 i686) [Netscape]">
</head>
<body>

<h1>
Additions to RandomArray module</h1>

<h2>
Lee A. Barford&nbsp;&nbsp; 18 December 1999</h2>
The RandomArray.py module distributed with the LLNL Distribution 11 contains
an interface to portions of the widely used and well tested random number
generation package ranlib. Ranlib is capable of generating floating point
random variables with a wide variety of probability density functions and
some kinds of discrete random variables as well. Random variables with
these nonuniform distributions have uses in diverse areas like Monte Carlo
simulation and the testing of signal processing algorithms. However, RandomArray.py
did not provide interfaces to those ranlib routines. This document describes
functions that have been added to module RandomArray to allow access to
all of the kinds of random variables provided by ranlib.
<h3>
Floating point random arrays</h3>
<i>standard_normal(shape=ReturnFloat)</i>
<br>The <tt>standard_normal()</tt> function returns an array of the specified
shape that contains double precision floating point numbers normally (Gaussian)
distributed with mean zero and variance and standard deviation one. If
no shape is specified, a single number is returned.
<p><i>normal(mean, variance, shape=ReturnFloat)</i>
<br>The <tt>normal()</tt> function returns an array of the specified shape
that contains double precision floating point numbers normally distributed
with the specified mean and variance. If no shape is specified, a single
number is returned.
<p><i>multivariate_normal(mean, covariance) or multivariate_normal(mean,
covariance, leadingAxesShape)</i>
<br>The <tt>multivariate_normal()</tt> function takes a one dimensional
array argument <tt>mean</tt> and a two dimensional array argument <tt>covariance.</tt>
Suppose the shape of <tt>mean</tt> is <tt>(n,). </tt>Then the shape of
<tt>covariance
</tt>must
be <tt>(n,n).</tt>&nbsp;&nbsp; The <tt>multivariate_normal()</tt> function
returns a double precision floating point array. The effect of the <tt>leadingAxesShape</tt>
parameter is:
<ul>
<li>
If no <tt>leadingAxesShape</tt> is specified, then an array with shape
<tt>(n,)</tt> is returned containing a vector of numbers with a multivariate
normal distribution with the specified mean and covariance.</li>

<li>
If <tt>leadingAxesShape</tt> is specified, then an array of such vectors
is returned. The shape of the output is <tt>leadingAxesShape.append((n,)).
</tt>The
leading indices into the output array select a multivariate normal from
the array. The final index selects one number from within the multivariate
normal.</li>
</ul>
In either case, the behavior of <tt>multivariate_normal()</tt> is undefined&nbsp;
if <tt>covariance </tt>is not symmetric and positive definite.
<p><i>exponential(mean, shape=ReturnFloat)</i>
<br>The <tt>exponential() </tt>function returns an array of the specified
shape that contains double precision floating point numbers exponentially
distributed with the specified mean. If no shape is specified, a single
number is returned.
<p><i>beta(a, b, shape=ReturnFloat)</i>
<br>The <tt>beta() </tt>function returns an array of the specified shape
that contains double precision floating point numbers beta distributed
with alpha parameter <tt>a </tt>and beta parameter <tt>b. </tt>If no shape
is specified, a single number is returned.
<p><i>gamma(a, r, shape=ReturnFloat)</i>
<br>The <tt>gamma() </tt>function returns an array of the specified shape
that contains double precision floating point numbers beta distributed
with location parameter <tt>a </tt>and distribution shape parameter <tt>r.
</tt>If no <tt>shape</tt> is specified, a single number is returned.
<p><i>chi_square(df, shape=ReturnFloat)</i>
<br>The <tt>chi_square()</tt> function returns an array of the specified
shape that contains double precision floating point numbers with the chi
square distribution with <tt>df</tt> degrees of freedom. If no shape is
specified, a single number is returned.
<p><i>noncentral_chi_square(df, nonc, shape=ReturnFloat)</i>
<br>The <tt>noncentral_chi_square()</tt> function returns an array of the
specified shape that contains double precision floating point numbers with
the chi square distribution with <tt>df </tt>degrees of freedom and noncentrality
parameter nconc. If no shape is specified, a single number is returned.
<p><i>F(dfn, dfd, shape=ReturnFloat)</i>
<br>The <tt>F()</tt> function returns an array of the specified shape that
contains double precision floating point numbers with the F distribution
with
<tt>dfn</tt> degrees of freedom in the numerator and <tt>dfd</tt>
degrees of freedom in the denominator. If no shape is specified, a single
number is returned.
<p><i>noncentral_F(dfn, dfd, nconc, shape=ReturnFloat)</i>
<br>The <tt>noncentral_F()</tt> function returns an array of the specified
shape that contains double precision floating point numbers with the F
distribution with <tt>dfn</tt> degrees of freedom in the numerator, <tt>dfd</tt>
degrees of freedom in the denominator, and noncentrality parameter <tt>nconc</tt>.
If no shape is specified, a single number is returned.
<h3>
Integer random arrays</h3>
<i>binomial(trials, prob, shape=ReturnInt)</i>
<br>The <tt>binomial()</tt> function returns an array with the specified
shape that contains integer numbers with the binomial distribution with
<tt>trials</tt>
trials and event probability <tt>prob</tt>. In other words, each value
in the returned array is the number of times an event with probability
<tt>prob
</tt>occurred
within <tt>trials </tt>repeated trials. If no shape is specified, a single
number is returned.
<p><i>negative_binomial(trials, prob, shape=ReturnInt)</i>
<br>The <tt>negative_binomial()</tt> function returns an array with the
specified shape that contains integer numbers with the negative binomial
distribution with <tt>trials</tt> trials and event probability <tt>prob</tt>.
If no shape is specified, a single number is returned.
<p><i>poisson(mean, shape=ReturnInt)</i>
<br>The <tt>poisson()</tt> function returns an array with the specified
shape that contains integer numbers with the Poisson distribution with
the specified mean. If no shape is specified, a single number is returned.
<p><i>multinomial(trials, probs) or multinomial(trials, probs, leadingAxesShape)</i>
<br>The <tt>multinomial()</tt> function returns an array with that contains
integer numbers with the multinomial distribution with <tt>trials</tt>
trials and event probabilities given in <tt>probs</tt>. <tt>probs</tt>
must be a one dimensional array. There are <tt>len(probs)+1</tt> events.
<tt>probs[i</tt>] is the probability of the <tt>i</tt>-th event for <tt>0&lt;=i&lt;len(probs)</tt>.
The probability of event <tt>len(probs)</tt> is <tt>1.-Numeric.sum(prob).</tt>
<p>The first form returns an integer array of shape <tt>(len(probs)+1,)</tt>
containing one multinomially distributed vector. The second form returns
an array of shape <tt>(m, n, ..., len(probs)+1)</tt> where <tt>(m, n, ...)</tt>
is <tt>leadingAxesShape</tt>. In this case, each
<tt>output[i,j,...,:]</tt>
is an integer array of shape <tt>(len(prob)+1,)</tt> containing one multinomially
distributed vector..
<h3>
Examples</h3>
Mostof the functions in this package take zero or more distribution specific
parameters plus an optional shape parameter. The shape parameter gives
the shape of the output array:
<blockquote><tt>Python 1.5.1 (#1, Mar 21 1999, 22:49:36) [GCC egcs-2.91.66
19990314/Li on linux-i386</tt>
<br><tt>Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam</tt>
<br><tt>>>> from RandomArray import *</tt>
<br><tt>>>> print standard_normal()</tt>
<br><tt>-0.435568600893</tt>
<br><tt>>>> print standard_normal(5)</tt>
<br><tt>[-1.36134553 0.78617644 -0.45038718 0.18508556 0.05941355]</tt>
<br><tt>>>> print standard_normal((5,2))</tt>
<br><tt>[[ 1.33448863 -0.10125473]</tt>
<br><tt>&nbsp;[ 0.66838062 0.24691346]</tt>
<br><tt>&nbsp;[-0.95092064 0.94168913]</tt>
<br><tt>&nbsp;[-0.23919107 1.89288616]</tt>
<br><tt>&nbsp;[ 0.87651485 0.96400219]]</tt>
<br><tt>>>> print normal(7., 4., (5,2)) % mean=7, std. dev.=4</tt>
<br><tt>[[ 2.66997623 11.65832615]</tt>
<br><tt>&nbsp;[ 6.73916003 6.58162862]</tt>
<br><tt>&nbsp;[ 8.47180378 4.30354905]</tt>
<br><tt>&nbsp;[ 1.35531998 -2.80886841]</tt>
<br><tt>&nbsp;[ 7.07408469 11.39024973]]</tt>
<br><tt>>>> print exponential(10., 5) % mean=10</tt>
<br><tt>[ 18.03347754 7.11702306 9.8587961 32.49231603 28.55408891]</tt>
<br><tt>>>> print beta(3.1, 9.1, 5) % alpha=3.1, beta=9.1</tt>
<br><tt>[ 0.1175056 0.17504358 0.3517828 0.06965593 0.43898219]</tt>
<br><tt>>>> print chi_square(7, 5) % 7 degrees of freedom (dfs)</tt>
<br><tt>[ 11.99046516 3.00741053 4.72235727 6.17056274 8.50756836]</tt>
<br><tt>>>> print noncentral_chi_square(7, 3, 5) % 7 dfs, noncentrality
3</tt>
<br><tt>[ 18.28332138 4.07550335 16.0425396 9.51192093 9.80156231]</tt>
<br><tt>>>> F(5, 7, 5) % 5 and 7 dfs</tt>
<br><tt>array([ 0.24693671, 3.76726145, 0.66883826, 0.59169068, 1.90763224])</tt>
<br><tt>>>> noncentral_F(5, 7, 3., 5) % 5 and 7 dfs, noncentrality 3</tt>
<br><tt>array([ 1.17992553, 0.7500126 , 0.77389943, 9.26798989, 1.35719634])</tt>
<br><tt>>>> binomial(32, .5, 5) % 32 trials, prob of an event = .5</tt>
<br><tt>array([12, 20, 21, 19, 17])</tt>
<br><tt>>>> negative_binomial(32, .5, 5) % 32 trials: prob of an event
= .5</tt>
<br><tt>array([21, 38, 29, 32, 36])</tt></blockquote>
Two functions that return generate multivariate random numbers (that is,
random vectors with some known relationship between the elements of each
vector, defined by the distribution).&nbsp; They are <tt>multivariate_normal()</tt>
and <tt>multinomial().</tt> For these two functions, the lengths of the
leading axes of the output may be specified. The length of the last axis
is determined by the length of some other parameter.
<blockquote><tt>>>> from Numeric import *</tt>
<br><tt>>>> multivariate_normal([1,2], [[1,2],[2,1]], [2,3])</tt>
<br><tt>array([[[ 0.14157988, 1.46232224],</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [-1.11820295, -0.82796288],</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ 1.35251635, -0.2575901
]],</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [[-0.61142141, 1.0230465 ],</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [-1.08280948, -0.55567217],</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ 2.49873002, 3.28136372]]])</tt>
<br><tt>>>> x = multivariate_normal([10,100], [[1,2],[2,1]], 10000)</tt>
<br><tt>>>> x_mean = sum(x)/10000</tt>
<br><tt>>>> print x_mean</tt>
<br><tt>[ 9.98599893 100.00032416]</tt>
<br><tt>>>> x_minus_mean = x - x_mean</tt>
<br><tt>>>> cov = matrixmultiply(transpose(x_minus_mean), x_minus_mean)
/ 9999.</tt>
<br><tt>>>> cov</tt>
<br><tt>array([[ 2.01737122, 1.00474408],</tt>
<br><tt>[ 1.00474408, 2.0009806 ]])</tt></blockquote>
The a priori probabilities for a multinomial distribution must sum to one.
The prior probability argument to <tt>multinomial()</tt> doesn't give the
prior probability of the last event: it is computed to be one minus the
sum of the others.
<blockquote><tt>>>> multinomial(16, [.1, .4, .2]) % prior probabilities
[.1, .4, .2, .3]</tt>
<br><tt>array([2, 7, 1, 6])</tt>
<br><tt>>>> multinomial(16, [.1, .4, .2], [2,3]) % output shape [2,3,4]</tt>
<br><tt>array([[[ 1, 9, 1, 5],</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ 0, 10, 3, 3],</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ 4, 9, 3, 0]],</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [[ 1, 6, 1, 8],</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ 3, 4, 5, 4],</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ 1, 5, 2, 8]]])</tt></blockquote>

</body>
</html>

--0-1804289383-945558422=:25420
Content-Type: text/plain; name="RandomArray-additions.txt"
Content-Description: RandomArray-additions.txt
Content-Disposition: inline; filename="RandomArray-additions.txt"

Additions to RandomArray module
Lee A. Barford   18 December 1999

The RandomArray.py module distributed with the LLNL Distribution 11
contains an interface to portions of the widely used and well tested
random number generation package ranlib. Ranlib is capable of
generating floating point random variables with a wide variety of
probability density functions and some kinds of discrete random
variables as well. Random variables with these nonuniform
distributions have uses in diverse areas like Monte Carlo simulation
and the testing of signal processing algorithms. However,
RandomArray.py did not provide interfaces to those ranlib
routines. This document describes functions that have been added to
module RandomArray to allow access to all of the kinds of random
variables provided by ranlib.

Floating point random arrays

standard_normal(shape=ReturnFloat) 

The standard_normal() function returns an array of the specified shape
that contains double precision floating point numbers normally
(Gaussian) distributed with mean zero and variance and standard
deviation one. If no shape is specified, a single number is returned.

normal(mean, variance, shape=ReturnFloat) 

The normal() function returns an array of the specified shape that
contains double precision floating point numbers normally distributed
with the specified mean and variance. If no shape is specified, a
single number is returned.

multivariate_normal(mean, covariance) or multivariate_normal(mean, covariance, leadingAxesShape) 

The multivariate_normal() function takes a one dimensional array
argument mean and a two dimensional array argument covariance. Suppose
the shape of mean is (n,). Then the shape of covariance must be
(n,n). The multivariate_normal() function returns a double precision
floating point array. The effect of the leadingAxesShape parameter is:

If no leadingAxesShape is specified, then an array with shape (n,) is
returned containing a vector of numbers with a multivariate normal
distribution with the specified mean and covariance.

If leadingAxesShape is specified, then an array of such vectors is
returned. The shape of the output is
leadingAxesShape.append((n,)). The leading indices into the output
array select a multivariate normal from the array. The final index
selects one number from within the multivariate normal.  In either
case, the behavior of multivariate_normal() is undefined if covariance
is not symmetric and positive definite.

exponential(mean, shape=ReturnFloat) 

The exponential() function returns an array of the specified shape
that contains double precision floating point numbers exponentially
distributed with the specified mean. If no shape is specified, a
single number is returned.

beta(a, b, shape=ReturnFloat) 

The beta() function returns an array of the specified shape that
contains double precision floating point numbers beta distributed with
alpha parameter a and beta parameter b. If no shape is specified, a
single number is returned.

gamma(a, r, shape=ReturnFloat) 

The gamma() function returns an array of the specified shape that
contains double precision floating point numbers beta distributed with
location parameter a and distribution shape parameter r. If no shape
is specified, a single number is returned.

chi_square(df, shape=ReturnFloat) 

The chi_square() function returns an array of the specified shape that
contains double precision floating point numbers with the chi square
distribution with df degrees of freedom. If no shape is specified, a
single number is returned.

noncentral_chi_square(df, nonc, shape=ReturnFloat)

The noncentral_chi_square() function returns an array of the specified
shape that contains double precision floating point numbers with the
chi square distribution with df degrees of freedom and noncentrality
parameter nconc. If no shape is specified, a single number is
returned.

F(dfn, dfd, shape=ReturnFloat) 

The F() function returns an array of the specified shape that contains
double precision floating point numbers with the F distribution with
dfn degrees of freedom in the numerator and dfd degrees of freedom in
the denominator. If no shape is specified, a single number is
returned.

noncentral_F(dfn, dfd, nconc, shape=ReturnFloat) 

The noncentral_F() function returns an array of the specified shape
that contains double precision floating point numbers with the F
distribution with dfn degrees of freedom in the numerator, dfd degrees
of freedom in the denominator, and noncentrality parameter nconc. If
no shape is specified, a single number is returned.

Integer random arrays

binomial(trials, prob, shape=ReturnInt) 

The binomial() function returns an array with the specified shape that
contains integer numbers with the binomial distribution with trials
trials and event probability prob. In other words, each value in the
returned array is the number of times an event with probability prob
occurred within trials repeated trials. If no shape is specified, a
single number is returned.

negative_binomial(trials, prob, shape=ReturnInt) 

The negative_binomial() function returns an array with the specified
shape that contains integer numbers with the negative binomial
distribution with trials trials and event probability prob. If no
shape is specified, a single number is returned.

poisson(mean, shape=ReturnInt) 

The poisson() function returns an array with the specified shape that
contains integer numbers with the Poisson distribution with the
specified mean. If no shape is specified, a single number is returned.

multinomial(trials, probs) or multinomial(trials, probs, leadingAxesShape) 

The multinomial() function returns an array with that contains integer
numbers with the multinomial distribution with trials trials and event
probabilities given in probs. probs must be a one dimensional
array. There are len(probs)+1 events. probs[i] is the probability of
the i-th event for 0<=i<len(probs). The probability of event
len(probs) is 1.-Numeric.sum(prob).  The first form returns an integer
array of shape (len(probs)+1,) containing one multinomially
distributed vector. The second form returns an array of shape (m, n,
..., len(probs)+1) where (m, n, ...) is leadingAxesShape. In this
case, each output[i,j,...,:] is an integer array of shape
(len(prob)+1,) containing one multinomially distributed vector..

Examples

Most of the functions in this package take zero or more distribution
specific parameters plus an optional shape parameter. The shape
parameter gives the shape of the output array:

Python 1.5.1 (#1, Mar 21 1999, 22:49:36) [GCC egcs-2.91.66 19990314/Li on linux-i386 
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam 
>>> from RandomArray import * 
>>> print standard_normal() 
-0.435568600893 
>>> print standard_normal(5) 
[-1.36134553 0.78617644 -0.45038718 0.18508556 0.05941355] 
>>> print standard_normal((5,2)) 
[[ 1.33448863 -0.10125473] 
 [ 0.66838062 0.24691346] 
 [-0.95092064 0.94168913] 
 [-0.23919107 1.89288616] 
 [ 0.87651485 0.96400219]] 
>>> print normal(7., 4., (5,2)) % mean=7, std. dev.=4 
[[ 2.66997623 11.65832615] 
 [ 6.73916003 6.58162862] 
 [ 8.47180378 4.30354905] 
 [ 1.35531998 -2.80886841] 
 [ 7.07408469 11.39024973]] 
>>> print exponential(10., 5) % mean=10 
[ 18.03347754 7.11702306 9.8587961 32.49231603 28.55408891] 
>>> print beta(3.1, 9.1, 5) % alpha=3.1, beta=9.1 
[ 0.1175056 0.17504358 0.3517828 0.06965593 0.43898219] 
>>> print chi_square(7, 5) % 7 degrees of freedom (dfs) 
[ 11.99046516 3.00741053 4.72235727 6.17056274 8.50756836] 
>>> print noncentral_chi_square(7, 3, 5) % 7 dfs, noncentrality 3 
[ 18.28332138 4.07550335 16.0425396 9.51192093 9.80156231] 
>>> F(5, 7, 5) % 5 and 7 dfs 
array([ 0.24693671, 3.76726145, 0.66883826, 0.59169068, 1.90763224]) 
>>> noncentral_F(5, 7, 3., 5) % 5 and 7 dfs, noncentrality 3 
array([ 1.17992553, 0.7500126 , 0.77389943, 9.26798989, 1.35719634]) 
>>> binomial(32, .5, 5) % 32 trials, prob of an event = .5 
array([12, 20, 21, 19, 17]) 
>>> negative_binomial(32, .5, 5) % 32 trials: prob of an event = .5 
array([21, 38, 29, 32, 36])

Two functions that return generate multivariate random numbers (that is, random vectors with some known relationship between the elements of each vector, defined by the distribution).  They are multivariate_normal() and multinomial(). For these two functions, the lengths of the leading axes of the output may be specified. The length of the last axis is determined by the length of some other parameter. 

>>> from Numeric import * 
>>> multivariate_normal([1,2], [[1,2],[2,1]], [2,3]) 
array([[[ 0.14157988, 1.46232224], 
        [-1.11820295, -0.82796288], 
        [ 1.35251635, -0.2575901 ]], 
       [[-0.61142141, 1.0230465 ], 
        [-1.08280948, -0.55567217], 
        [ 2.49873002, 3.28136372]]]) 
>>> x = multivariate_normal([10,100], [[1,2],[2,1]], 10000) 
>>> x_mean = sum(x)/10000 
>>> print x_mean 
[ 9.98599893 100.00032416] 
>>> x_minus_mean = x - x_mean 
>>> cov = matrixmultiply(transpose(x_minus_mean), x_minus_mean) / 9999. 
>>> cov 
array([[ 2.01737122, 1.00474408], 
[ 1.00474408, 2.0009806 ]])

The a priori probabilities for a multinomial distribution must sum to
one. The prior probability argument to multinomial() doesn't give the
prior probability of the last event: it is computed to be one minus
the sum of the others.

>>> multinomial(16, [.1, .4, .2]) % prior probabilities [.1, .4, .2, .3] 
array([2, 7, 1, 6]) 
>>> multinomial(16, [.1, .4, .2], [2,3]) % output shape [2,3,4] 
array([[[ 1, 9, 1, 5], 
        [ 0, 10, 3, 3], 
        [ 4, 9, 3, 0]], 
       [[ 1, 6, 1, 8], 
        [ 3, 4, 5, 4], 
        [ 1, 5, 2, 8]]])

--0-1804289383-945558422=:25420
Content-Type: application/x-unknown; name="RandomArray.patch"
Content-Transfer-Encoding: base64
Content-Description: RandomArray.patch
Content-Disposition: attachment; filename="RandomArray.patch"

ZGlmZiAtLWNvbnRleHQgLS1yZWN1cnNpdmUgTnVtZXJpY2FsLW9yaWcvTGli
L1JhbmRvbUFycmF5LnB5IE51bWVyaWNhbC9MaWIvUmFuZG9tQXJyYXkucHkK
KioqIE51bWVyaWNhbC1vcmlnL0xpYi9SYW5kb21BcnJheS5weQlTYXQgRGVj
IDE4IDE0OjE1OjEwIDE5OTkKLS0tIE51bWVyaWNhbC9MaWIvUmFuZG9tQXJy
YXkucHkJU2F0IERlYyAxOCAxMDo1NzoyOSAxOTk5CioqKioqKioqKioqKioq
KgoqKiogMSw5ICoqKioKLS0tIDEsMTUgLS0tLQogIGltcG9ydCByYW5saWIK
ICBpbXBvcnQgTnVtZXJpYworIGltcG9ydCBMaW5lYXJBbG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KSApCisgICAgICAg
cmV0dXJuIE5VTEw7CisgICAgIGJyZWFrOworICAgY2FzZSAxOgorICAgICBp
ZiggIVB5QXJnX1BhcnNlVHVwbGUoYXJncywgImZ8aSIsICZhLCAmbikgKQor
ICAgICAgIHJldHVybiBOVUxMOworICAgICBicmVhazsKKyAgIGNhc2UgMjoK
KyAgICAgaWYoICFQeUFyZ19QYXJzZVR1cGxlKGFyZ3MsICJmZnxpIiwgJmEs
ICZiLCAmbikgKQorICAgICAgIHJldHVybiBOVUxMOworICAgICBicmVhazsK
KyAgIGNhc2UgMzoKKyAgICAgaWYoICFQeUFyZ19QYXJzZVR1cGxlKGFyZ3Ms
ICJmZmZ8aSIsICZhLCAmYiwgJmMsICZuKSApCisgICAgICAgcmV0dXJuIE5V
TEw7CisgICAgIGJyZWFrOworICAgfQorICAgaWYoIG4gPT0gLTEgKQorICAg
ICBuID0gMTsKKyAKKyAgIC8qIENyZWF0ZSBhIDEgZGltZW5zaW9uYWwgYXJy
YXkgb2YgbGVuZ3RoIG4gb2YgdHlwZSBkb3VibGUgKi8KKyAgIG9wID0gKFB5
QXJyYXlPYmplY3QqKSBQeUFycmF5X0Zyb21EaW1zKDEsICZuLCBQeUFycmF5
X0RPVUJMRSk7CisgICBpZiggb3AgPT0gTlVMTCApCisgICAgIHJldHVybiBO
VUxMOworIAorICAgb3V0X3B0ciA9IChkb3VibGUgKikgb3AtPmRhdGE7Cisg
ICBmb3IoaT0wOyBpPG47IGkrKykgeworICAgICBzd2l0Y2gobnVtX2Rpc3Rf
cGFyYW1zKSB7CisgICAgIGNhc2UgMDoKKyAgICAgICAqb3V0X3B0ciA9IChk
b3VibGUpICgoZmxvYXQgKCopKCkpIGZ1bikoKTsKKyAgICAgICBicmVhazsK
KyAgICAgY2FzZSAxOgorICAgICAgICpvdXRfcHRyID0gKGRvdWJsZSkgKChm
bG9hdCAoKikoZmxvYXQpKSBmdW4pKGEpOworICAgICAgIGJyZWFrOworICAg
ICBjYXNlIDI6CisgIC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0ZhdGFsRXJyb3IoImNhbid0IGluaXRpYWxpemUgbW9kdWxlIHJhbmxp
YiIpOwogIH0KLSAKLSAKLSAKLSAKLS0tIDMyMCwzMjIgLS0tLQo=

--0-1804289383-945558422=:25420--