python 矩阵随机生成

来源:互联网 发布:java volatile的用法 编辑:程序博客网 时间:2024/06/05 11:49

Generate a sparse matrix


Generate a sparse matrix of the given shape and density with uniformly distributed values.

scipy.sparse.rand(mndensity=0.01format='coo'dtype=Nonerandom_state=None)


Parameters:
m, n : int
shape of the matrix
density : real, optional
density of the generated matrix: density equal to one means a full matrix, densityof 0 means a matrix with no non-zero items.
format : str, optional
sparse matrix format.
dtype : dtype, optional
type of the returned matrix values.
random_state : {numpy.random.RandomState, int}, optional
Random number generator or random seed. If not given, the singleton numpy.randomwill be used.

example:

>>> sp.rand(4,3,density=1,).todense()
matrix([[ 0.54318062,  0.73848674,  0.66199091],
     [ 0.55778929,  0.74904161,  0.97990645],
     [ 0.92667378,  0.07833997,  0.18023915],
     [ 0.02989316,  0.88534361,  0.00998536]])

0 0
原创粉丝点击