熟悉ndarray创建的不同方式(扩展补充):
至于常用的一些创建方式,在这篇博文中已经写过,这次主要是对用random创建进行补充
1. rand
查看帮助文档: (部分)
Create an array of the given shape and populate it with
random samples from a uniform distribution
over [0, 1).
理解:
可以给rand传入n个参数,最终得出n维数组,n只允许传入int型,返回的数组中的数字大小范围是 [0,1) 注意区间
例如:
2. randn
查看帮助文档:(部分)
Return a sample (or samples) from the "standard normal" distribution.
理解:
可以传多参数,返回一个或一组样本具有正态分布
例如:
3. randint
查看帮助文档:(部分)
randint(low, high=None, size=None, dtype='l')
Return random integers from `low` (inclusive) to `high` (exclusive).
Return random integers from the "discrete uniform" distribution of
the specified dtype in the "half-open" interval [`low`, `high`). If
`high` is None (the default), then results are from [0, `low`).
理解:
可以传三参数:low(默认0)、high(默认None)、size(默认None),最后生成在半开半闭区间[low,high)上离散均匀分布的整数值;若high=None,则取值区间变为[0,low) 注意区间
例如:
4. random_integer
查看帮助文档:(部分)
random_integers(...) method of mtrand.RandomState instance
random_integers(low, high=None, size=None)
Random integers of type np.int between `low` and `high`, inclusive.
Return random integers of type np.int from the "discrete uniform"
distribution in the closed interval [`low`, `high`]. If `high` is
None (the default), then results are from [1, `low`]. The np.int
type translates to the C long type used by Python 2 for "short"
integers and its precision is platform dependent.
理解:
可以传三参数:low(默认0)、high(默认None)、size(默认None),最后生成闭区间[low,high]上离散均匀分布的整数值;若high=None,则取值区间变为[1,low] 注意区间
例如: