import numpy as np

生成 3*4 的由  0 组成的二维数组

>>> np.zeros((3,4))

array([[0., 0., 0., 0.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]])

生成  2*3*4   的由  1 组成的三维数组

>>>np.ones((2,3,4),dtype=np.int16)

array([[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]],

[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]]], dtype=int16)

生成 10 ~25 间的 间隔为5的数列

>>>np.arange(10,25,5)

array([10, 15, 20])

生成 0~2间的等差数列,元素个数 为 9

>>>np.linspace(0,2,9)

array([0.  , 0.25, 0.5 , 0.75, 1.  , 1.25, 1.5 , 1.75, 2.  ])

以给定数 7 ,生成 指定形状2*2的矩阵

>>> np.full((2,2),7)
array([[7, 7],
[7, 7]])

生成对角矩阵, 长与宽相等 ,默认中间对角线(左上到右下)全是1,其余为0

>>np.eye(2)

array([[1., 0.],
[0., 1.]])

生成数值在1以内的指定形状 2*2 的随机矩阵

>>> np.random.random((2,2))
array([[0.36248815, 0.60881839],
[0.10805521, 0.92618553]])

生成指定形状的空数组,数组内数据,可能是随机的

empty, unlike zeros, does not set the array values to zero, and may therefore be marginally faster. On the other hand, it requires the user to manually set all the values in the array, and should be used with caution.

>>np.empty((3,2))

array([[1.39069238e-309, 1.39069238e-309],
[1.39069238e-309, 1.39069238e-309],
[1.39069238e-309, 1.39069238e-309]])

 

numpy 小示例的更多相关文章

  1. ReactNative新手学习之路06滚动更新ListView数据的小示例

    本节带领大家学习使用ListView 做一个常用的滚动更新数据示例: 知识点: initialListSize={200} 第一次加载多少数据行 onEndReached={this.onEndRea ...

  2. MVC客户端验证的小示例

    MVC客户端验证的小示例 配置客户端验证的可用性: <configuration> <appSettings>  <add key="ClientValidat ...

  3. 【.Net】Socket小示例

    引言 项目中用到了Socket,这里做个控制台小示例记录一下. Client 客户端的Receive用了异步方法,保持长连接,可以随时发送消息和响应服务端的消息,如下 static string Cl ...

  4. CentOS7 安装 RocketMQ 实践和小示例

    CentOS7 安装 RocketMQ 实践和小示例 1.通过 SSH 工具(比如 XShell)连接到 CentOS7 服务器上: 2.进入到 /usr/local 目录中: cd /usr/loc ...

  5. Highcharts入门小示例

    一.创建条形图 1.创建div容器 <div id="container" style="min-width:800px;height:400px"> ...

  6. matplotlib小示例

    matplotlib 画廊  http://matplotlib.org/gallery.html import numpy as np import matplotlib.pyplot as plt ...

  7. NHibernate 集合映射基础(第四篇) - 一对一、 一对多、多对多小示例

    映射文件,用于告诉NHibernate数据库里的表.列于.Net程序中的类的关系.因此映射文件的配置非常重要. 一.一对一 NHibernate一对一关系的配置方式使用<one-to-one&g ...

  8. numpy使用示例

    numpy介绍 创建numpy的数 一维数组是什么样子 可以理解为格子纸的一行就是一个一维数据 two_arr = np.array([1, 2, 3]) 二维数组什么样子 理解为一张格子纸, 多个一 ...

  9. TensorFlow系列专题(八):七步带你实现RNN循环神经网络小示例

    欢迎大家关注我们的网站和系列教程:http://panchuang.net/ ,学习更多的机器学习.深度学习的知识! [前言]:在前面的内容里,我们已经学习了循环神经网络的基本结构和运算过程,这一小节 ...

随机推荐

  1. bootstrap4

    lipsum, lorem生成假文, 是在编辑器中按tab键时生成的, 那个时候就已经生成了, 所以你在浏览器上看到的内容就是编辑器中的内容, 这个内容不会再变了. 所以你不要企图想刷新浏览器而改变假 ...

  2. springboot集成shiro 前后端分离

    前后端分离情况下 首先考虑是否跨域,如果没有跨域是可以使用shiro原生的session+cookie,无需特别处理. 如果涉及到跨域则需要考虑cookie问题(本质上也是重写shiro获取JESSI ...

  3. dubbo 实战总结

    1,出现重复调用.因为有重试机制,可以改为异步调用或者幂等操作.

  4. hbase读写流程分析

    前言 最近被大佬问到一个问题,hbase查询数据在最坏的场景下需要进行几次rpc,当时就懵了..下面主要对client端代码进行分析.阅读文章和看源码更配~ 读数据 流程总览 1. 从zookeepe ...

  5. samba基本应用24-4及示例

    samba smb:service message block(137/udp, 138/udp, 139/tcp, 445/tcp) 协议是:CIFS:Common Internet File Sy ...

  6. 02_Spark Application不同模式下的监控

    监控Spark Application的运行 官方文档: http://spark.apache.org/docs/latest/monitoring.html 1.1 监控方式 Driver Pro ...

  7. C++:为什么unique_ptr的Deleter是模板类型参数,而shared_ptr的Deleter不是?

    为什么unique_ptr的Deleter是模板类型参数,而shared_ptr的Deleter不是? template <class T, class D = default_delete&l ...

  8. ubuntu 16.04 u盘挂载以及卸载

    1.列出所有磁盘 sudo fdisk -l 2.最后一段信息显示的为u盘 Device Boot Start End Sectors Size Id Type /dev/sdb4 * 256 786 ...

  9. Linux 设置定时任务 清空日志

    Step 1:前提是linux服务器安装了crond 定时任务需要crond服务的支持 1.启动方法 service crond restart 2.该服务默认是开机启动的 取消定时任务 1.全部取消 ...

  10. JS 字符串 作为变量名

    function initCKEditor(querySelector,content_val,myEditor) { ClassicEditor.create(document.querySelec ...