[云炬python3玩转机器学习笔记] 3-4创建Numpy数组和矩阵
其他创建 numpy.array的方法
np.zeros(10)
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
np.zeros(10).dtype
dtype('float64')
np.zeros(10,dtype=int)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
np.zeros((3,5))
array([[0., 0., 0., 0., 0.],[0., 0., 0., 0., 0.],[0., 0., 0., 0., 0.]])
np.zeros(shape=(3,5), dtype=int)
array([[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]])
np.ones(10)
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
np.ones((3,5))
array([[1., 1., 1., 1., 1.],[1., 1., 1., 1., 1.],[1., 1., 1., 1., 1.]])
np.full(shape=(3,5),fill_value=666.0)
array([[666., 666., 666., 666., 666.],[666., 666., 666., 666., 666.],[666., 666., 666., 666., 666.]])
np.full(fill_value=666.0, shape=(3,5))
array([[666., 666., 666., 666., 666.],[666., 666., 666., 666., 666.],[666., 666., 666., 666., 666.]])
arange
[i for i in range(0,20,2)]
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
np.arange(0,20,2)
array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])
[i for i in range(0,1,0.2)]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-46-be9c9326671d> in <module>
----> 1 [i for i in range(0,1,0.2)]TypeError: 'float' object cannot be interpreted as an integer
np.arange(0,1,0.2)
array([0. , 0.2, 0.4, 0.6, 0.8])
np.arange(0,10)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
np.arange(10)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Linespace
np.linspace(0,20,10)
array([ 0. , 2.22222222, 4.44444444, 6.66666667, 8.88888889,11.11111111, 13.33333333, 15.55555556, 17.77777778, 20. ])
np.linspace(0,20,11)
array([ 0., 2., 4., 6., 8., 10., 12., 14., 16., 18., 20.])
random
np.random.randint(0,10)
3
np.random.randint(0,10,10)
array([0, 3, 2, 6, 4, 6, 4, 9, 5, 9])
np.random.randint(0,1,10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
np.random.randint(4,8,size=10)
array([5, 4, 7, 7, 7, 5, 7, 7, 6, 5])
np.random.randint(4,8,size=(3,5))
array([[4, 5, 5, 5, 5],[7, 4, 6, 5, 6],[5, 6, 7, 6, 7]])
np.random.randint(4,8,size=(3,5))
array([[6, 4, 4, 4, 5],[6, 5, 7, 4, 4],[7, 6, 4, 6, 6]])
np.random.seed(666)
np.random.randint(4,8,size=(3,5))
array([[4, 6, 5, 6, 6],[6, 5, 6, 4, 5],[7, 6, 7, 4, 7]])
np.random.seed(666)
np.random.randint(4,8,size=(3,5))
array([[4, 6, 5, 6, 6],[6, 5, 6, 4, 5],[7, 6, 7, 4, 7]])
np.random.random()
0.2811684913927954
np.random.random(10)
array([0.92389692, 0.29489453, 0.52438061, 0.94253896, 0.07473949,0.27646251, 0.4675855 , 0.31581532, 0.39016259, 0.26832981])
np.random.random((3,5))
array([[0.75366384, 0.66673747, 0.87287954, 0.52109719, 0.75020425],[0.32940234, 0.29130197, 0.00103619, 0.6361797 , 0.97933558],[0.91236279, 0.39925165, 0.40322917, 0.33454934, 0.72306649]])
np.random.normal()
-0.27084406682175244
np.random.normal(10,100)
90.97649843106657
np.random.normal(0,1,(3,5))
array([[ 1.85205227, 1.67819021, -0.98076924, 0.47031082, 0.18226991],[-0.84388249, 0.20996833, 0.22958666, 0.26307642, 2.16633222],[-1.04887593, -1.84768442, 0.53401503, -1.19574802, -0.28915737]])
np.random.normal?
np.random?
help(np.random.normal)
Help on built-in function normal:normal(...) method of numpy.random.mtrand.RandomState instancenormal(loc=0.0, scale=1.0, size=None)Draw random samples from a normal (Gaussian) distribution.The probability density function of the normal distribution, firstderived by De Moivre and 200 years later by both Gauss and Laplaceindependently [2]_, is often called the bell curve because ofits characteristic shape (see the example below).The normal distributions occurs often in nature. For example, itdescribes the commonly occurring distribution of samples influencedby a large number of tiny, random disturbances, each with its ownunique distribution [2]_... note::New code should use the ``normal`` method of a ``default_rng()``instance instead; please see the :ref:`random-quick-start`.Parameters----------loc : float or array_like of floatsMean ("centre") of the distribution.scale : float or array_like of floatsStandard deviation (spread or "width") of the distribution. Must benon-negative.size : int or tuple of ints, optionalOutput shape. If the given shape is, e.g., ``(m, n, k)``, then``m * n * k`` samples are drawn. If size is ``None`` (default),a single value is returned if ``loc`` and ``scale`` are both scalars.Otherwise, ``np.broadcast(loc, scale).size`` samples are drawn.Returns-------out : ndarray or scalarDrawn samples from the parameterized normal distribution.See Also--------scipy.stats.norm : probability density function, distribution orcumulative density function, etc.Generator.normal: which should be used for new code.Notes-----The probability density for the Gaussian distribution is.. math:: p(x) = \frac{1}{\sqrt{ 2 \pi \sigma^2 }}e^{ - \frac{ (x - \mu)^2 } {2 \sigma^2} },where :math:`\mu` is the mean and :math:`\sigma` the standarddeviation. The square of the standard deviation, :math:`\sigma^2`,is called the variance.The function has its peak at the mean, and its "spread" increases withthe standard deviation (the function reaches 0.607 times its maximum at:math:`x + \sigma` and :math:`x - \sigma` [2]_). This implies thatnormal is more likely to return samples lying close to the mean, ratherthan those far away.References----------.. [1] Wikipedia, "Normal distribution",https://en.wikipedia.org/wiki/Normal_distribution.. [2] P. R. Peebles Jr., "Central Limit Theorem" in "Probability,Random Variables and Random Signal Principles", 4th ed., 2001,pp. 51, 51, 125.Examples--------Draw samples from the distribution:>>> mu, sigma = 0, 0.1 # mean and standard deviation>>> s = np.random.normal(mu, sigma, 1000)Verify the mean and the variance:>>> abs(mu - np.mean(s))0.0 # may vary>>> abs(sigma - np.std(s, ddof=1))0.1 # may varyDisplay the histogram of the samples, along withthe probability density function:>>> import matplotlib.pyplot as plt>>> count, bins, ignored = plt.hist(s, 30, density=True)>>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *... np.exp( - (bins - mu)**2 / (2 * sigma**2) ),... linewidth=2, color='r')>>> plt.show()Two-by-four array of samples from N(3, 6.25):>>> np.random.normal(3, 2.5, size=(2, 4))array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
[云炬python3玩转机器学习笔记] 3-4创建Numpy数组和矩阵相关推荐
- [云炬python3玩转机器学习笔记] 1-3课程所使用的主要技术栈
课程环境 语言:Python3 框架:Scikit-learn 其他框架:numpy,matplotlib... IDE:Jupyter Notebook,PyCharm,ANACONDA 课程学习基 ...
- [云炬python3玩转机器学习笔记] 3-2 Jupter Notebook魔法命令
xxxxxxxxxx### %run %run¶ In [1]:%run myscript/hello.py hello Machine Learning ! . . .In [2]:xxxxxxxx ...
- [云炬python3玩转机器学习笔记] 3-1 Jupyter Notebook
1+2for _ in range(5):print("Hello, Machine Learning!")5+5*29+9print("天津云炬网络科技有限公司&quo ...
- [云炬python3玩转机器学习笔记] 2-7开发环境搭建笔记
开发环境搭建笔记
- [云炬python3玩转机器学习笔记] 2-6关于回归和分类
在这一章,我们了解到了,机器学习主要可以处理的两大类问题,是回归和分类.看起来,似乎有些局限,但是,非常出人意料的,在我们现实生活中,很多问题,都可以通过化简,或者转换的手段,转换成分类问题或者回归问 ...
- [云炬python3玩转机器学习笔记] 2-5机器学习相关的哲学思考
2-5机器学习相关的哲学思考
- [云炬python3玩转机器学习笔记] 2-4批量学习、咋西安学习、参数学习和非参数学习
机器学习的其他分类: 在线学习(online learining)和批量学习(离线学习 batch learning/offline learning): 批量学习(之前没有具体说明的话,都可以用批量 ...
- [云炬python3玩转机器学习笔记] 2-2机器学习主要任务
机器学习(监督学习)的主要任务 一.分类:将给定的数据进行分类- 二分类任务:二选一的方式,yes/no- 多分类任务:结果不仅仅在两个结果中,而是很多结果,获得的结果很明确- 数字识别- 图像识别- ...
- [云炬python3玩转机器学习笔记] 2-1机器学习基础概念
机器学习基础概念 一.关于数据 本文约定: 大写表示矩阵 小写表示向量 上标代表第几个样本 下标代表第几个特征 一般向量都表示为列向量 特征空间:每个维度都可以表示一个特征,形成一个空间(2D,3D, ...
- [云炬python3玩转机器学习笔记] 1-1什么是机器学习
一. 什么是机器学习 机器学习本质是在模拟人类进行思考学习,人类的思考学习大部分来自经验的积累,机器学习也一样 二.机器学习的应用场景 (一)已投入生产的 (二)未来需要运用机器学习的领域 在未来,A ...
最新文章
- 80页笔记看遍机器学习基本概念、算法、模型,帮新手少走弯路
- JAVA编译异常处理:java.lang.OutOfMemoryError: PermGen space
- java泛型程序设计——无限定通配符+通配符捕获
- iOS NSString 与NSData转化
- Java Web学习笔记05:状态管理
- gitlab简单使用教程【转】
- 我为什么建议你发年终奖前跳槽?
- linux内核配置usb虚拟串口,霍尼韦尔是否能提供USB串口仿真的Linux驱动程序?
- 廖雪峰Git学习 | 笔记二:修改以及版本回退
- 【实战毕业论文排版】图片添加题注实现自动编号
- 微型计算机硬件列表,微型计算机的硬件组成 | 学步园
- 吉林大学计算机学院林丛郁,吉林大学珠海学院201奖学金
- 为什么现在很多人在用影刀,影刀突然火起来了?
- CATIA V6二次开发——Automation之对象
- 机器人波波熊_【菠菠智能悦读机器人绘本更新篇】新技能get!BoBo本周新增绘本103本!...
- 《用C#制作PDF文件全攻略》
- 基于ViewFlipper实现图片浏览组件
- Python 文件I/Oday14
- 基于角色管理的简易家谱管理系统(C++/C(几乎都是C))2020-06-16
- 干货-运行Python脚本的命令行操作(2)