On Wed, Sep 25, 2013 at 8:06 AM, Edmondo Porcu <edmondo.po...@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@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion