其他创建 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数组和矩阵相关推荐

  1. [云炬python3玩转机器学习笔记] 1-3课程所使用的主要技术栈

    课程环境 语言:Python3 框架:Scikit-learn 其他框架:numpy,matplotlib... IDE:Jupyter Notebook,PyCharm,ANACONDA 课程学习基 ...

  2. [云炬python3玩转机器学习笔记] 3-2 Jupter Notebook魔法命令

    xxxxxxxxxx### %run %run¶ In [1]:%run myscript/hello.py hello Machine Learning ! . . .In [2]:xxxxxxxx ...

  3. [云炬python3玩转机器学习笔记] 3-1 Jupyter Notebook

    1+2for _ in range(5):print("Hello, Machine Learning!")5+5*29+9print("天津云炬网络科技有限公司&quo ...

  4. [云炬python3玩转机器学习笔记] 2-7开发环境搭建笔记

    开发环境搭建笔记

  5. [云炬python3玩转机器学习笔记] 2-6关于回归和分类

    在这一章,我们了解到了,机器学习主要可以处理的两大类问题,是回归和分类.看起来,似乎有些局限,但是,非常出人意料的,在我们现实生活中,很多问题,都可以通过化简,或者转换的手段,转换成分类问题或者回归问 ...

  6. [云炬python3玩转机器学习笔记] 2-5机器学习相关的哲学思考

    2-5机器学习相关的哲学思考

  7. [云炬python3玩转机器学习笔记] 2-4批量学习、咋西安学习、参数学习和非参数学习

    机器学习的其他分类: 在线学习(online learining)和批量学习(离线学习 batch learning/offline learning): 批量学习(之前没有具体说明的话,都可以用批量 ...

  8. [云炬python3玩转机器学习笔记] 2-2机器学习主要任务

    机器学习(监督学习)的主要任务 一.分类:将给定的数据进行分类- 二分类任务:二选一的方式,yes/no- 多分类任务:结果不仅仅在两个结果中,而是很多结果,获得的结果很明确- 数字识别- 图像识别- ...

  9. [云炬python3玩转机器学习笔记] 2-1机器学习基础概念

    机器学习基础概念 一.关于数据 本文约定: 大写表示矩阵 小写表示向量 上标代表第几个样本 下标代表第几个特征 一般向量都表示为列向量 特征空间:每个维度都可以表示一个特征,形成一个空间(2D,3D, ...

  10. [云炬python3玩转机器学习笔记] 1-1什么是机器学习

    一. 什么是机器学习 机器学习本质是在模拟人类进行思考学习,人类的思考学习大部分来自经验的积累,机器学习也一样 二.机器学习的应用场景 (一)已投入生产的 (二)未来需要运用机器学习的领域 在未来,A ...

最新文章

  1. Python函数Day1
  2. Mac终端显示 bogon的问题
  3. 用Python的Tultle模块创建一个五角星
  4. C#学习笔记(十三):I/O操作
  5. POJ2823 Sliding Window 单调队列
  6. Hibernate常见面试题
  7. 金九银十加薪季,测试题预热一波。
  8. Unix网络编程 chart
  9. 做一个计算器_如何设计一个JavaScript插件系统,编程思维比死磕API更重要
  10. python股票交易系统实现_python实现股票自动交易,自动量化交易软件
  11. php数组中去掉空格,php数组如何去除空格
  12. 电信光猫HG2201T超级管理员模式
  13. uni-app使用小图标的方式
  14. 数据中心到底是如何建设的?
  15. 第1060期AI100_机器学习日报(2017-08-13)
  16. 支付宝支付-APP支付服务端详解
  17. Tomcat中temp文件夹出现项目副本问题的解决方法
  18. package-lock和package-shrinkwrap
  19. WimTool安装使用方法
  20. 我为什么开始写博客,并要坚持下去?

热门文章

  1. 5G时代 我国在通信技术领域弯道超车指日可待
  2. 【更新链接】U盘启动制作工具(UDTOOL) v3.0.2014.0427
  3. DLINK DES3828三层交换机配置实例
  4. Linux代理服务器与防火墙安装与应用
  5. Apache 2.2 + Php 5.1 安装问题解决[原创]
  6. NYOJ 38 布线问题
  7. 判断两条线段是否相交
  8. 微信小程序~自定义属性设置和获取(data-)
  9. 什么是Session共享?请举出使用场景
  10. JAVA面试整理之——JAVA基础