def uniform(size, low=None, high=None, dtype=numpy.float32):
if dtype is numpy.float32 or dtype is numpy.float64:
if low is None:
low = -numpy.sqrt(6. / sum(size))
if high is None:
high = numpy.sqrt(6. / sum(size))
return numpy.asarray(
numpy.random.uniform(
low=low,
high=high,
size=size
),
dtype=dtype)
elif dtype is numpy.complex64:
return (uniform(size, low=low, high=high, dtype=numpy.float32) +
1j * uniform(size, low=low, high=high,
dtype=numpy.float32)).astype(numpy.complex64)
elif dtype is numpy.complex128:
return (uniform(size, low=low, high=high, dtype=numpy.float64) +
1j * uniform(size, low=low, high=high,
dtype=numpy.float64)).astype(numpy.complex128)
else:
raise ValueError('Requested dtype not available.')
评论列表
文章目录