[Numpy-discussion] Numpy newbie question: matrix creation

Edmondo Porcu edmondo.porcu at gmail.com
Wed Sep 25 08:12:15 EDT 2013


That's what I was looking for, except that I want to be sure to generate
all the possible combinations, and to have no repeated values.

Thanks

Edmondo


2013/9/25 Robert Kern <robert.kern at gmail.com>

> On Wed, Sep 25, 2013 at 8:06 AM, Edmondo Porcu <edmondo.porcu at gmail.com>
> wrote:
> >
> > Dear all,
> >
> > I am a Newbie with Numpy and I would need some advice on how to create a
> matrix with certain characteristics :
> >
> >  - Every entry should be minimum 0 maximum 1 with a step of 0.1 (legal
> values are 0,0.1,0.2,0.3 etc)
> >
> > - The number of columns of the matrix is a parameter of this matrix
> creation algorithm
> >
> > - Only the rows where the sum is 1 must be kept
> >
> > Would great appreciate your advice and suggestions
>
> Use a multinomial distribution with n=10, then divide by 10.0.
>
> For example, with 5 columns and 20 samples:
>
> [~]
> |4> np.random.multinomial(10, np.ones(5)/5.0, size=20) / 10.0
> array([[ 0.1,  0.1,  0.4,  0.1,  0.3],
>        [ 0.2,  0.4,  0.1,  0.3,  0. ],
>        [ 0.3,  0.2,  0. ,  0.2,  0.3],
>        [ 0. ,  0.4,  0.4,  0. ,  0.2],
>        [ 0.2,  0.3,  0.1,  0.2,  0.2],
>        [ 0.1,  0.5,  0.1,  0.1,  0.2],
>        [ 0.4,  0. ,  0.2,  0.3,  0.1],
>        [ 0.3,  0.3,  0.1,  0. ,  0.3],
>        [ 0. ,  0.2,  0.5,  0.2,  0.1],
>        [ 0.5,  0.1,  0. ,  0.2,  0.2],
>        [ 0.1,  0.3,  0.2,  0.2,  0.2],
>        [ 0.3,  0.1,  0.2,  0.2,  0.2],
>        [ 0.2,  0.3,  0. ,  0.3,  0.2],
>        [ 0.2,  0.3,  0.2,  0.3,  0. ],
>        [ 0.1,  0.3,  0.2,  0. ,  0.4],
>        [ 0.1,  0.1,  0.2,  0.5,  0.1],
>        [ 0.1,  0.6,  0. ,  0. ,  0.3],
>        [ 0.1,  0.2,  0.4,  0.1,  0.2],
>        [ 0.3,  0.1,  0.2,  0.2,  0.2],
>        [ 0.2,  0.1,  0.4,  0.2,  0.1]])
>
> --
> Robert Kern
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130925/ae88e461/attachment.html>


More information about the NumPy-Discussion mailing list