python中numpy.zeros(np.zeros)的使用方法


Posted in Python onNovember 07, 2017

翻译:

用法:zeros(shape, dtype=float, order='C')

返回:返回来一个给定形状和类型的用0填充的数组;

参数:shape:形状

dtype:数据类型,可选参数,默认numpy.float64

dtype类型:

t ,位域,如t4代表4位

b,布尔值,true or false

i,整数,如i8(64位)

u,无符号整数,u8(64位)

f,浮点数,f8(64位)

c,浮点负数,

o,对象,

s,a,字符串,s24

u,unicode,u24

order:可选参数,c代表与c语言类似,行优先;F代表列优先

例子:

np.zeros(5)
array([ 0., 0., 0., 0., 0.])


np.zeros((5,), dtype=np.int)
array([0, 0, 0, 0, 0])


np.zeros((2, 1))
array([[ 0.],
    [ 0.]])


s = (2,2)
np.zeros(s)
array([[ 0., 0.],
    [ 0., 0.]])


np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype
array([(0, 0), (0, 0)],
   dtype=[('x', '<i4'), ('y', '<i4')])


########################################################

zeros(shape, dtype=float, order='C')



Return a new array of given shape and type, filled with zeros.


Parameters
----------
shape : int or sequence of ints
  Shape of the new array, e.g., ``(2, 3)`` or ``2``.
dtype : data-type, optional
  The desired data-type for the array, e.g., `numpy.int8`. Default is
  `numpy.float64`.
order : {'C', 'F'}, optional
  Whether to store multidimensional data in C- or Fortran-contiguous
  (row- or column-wise) order in memory.


Returns
-------
out : ndarray
  Array of zeros with the given shape, dtype, and order.


See Also
--------
zeros_like : Return an array of zeros with shape and type of input.
ones_like : Return an array of ones with shape and type of input.
empty_like : Return an empty array with shape and type of input.
ones : Return a new array setting values to one.
empty : Return a new uninitialized array.


Examples
--------
np.zeros(5)
array([ 0., 0., 0., 0., 0.])


np.zeros((5,), dtype=np.int)
array([0, 0, 0, 0, 0])


np.zeros((2, 1))
array([[ 0.],
    [ 0.]])


s = (2,2)
np.zeros(s)
array([[ 0., 0.],
    [ 0., 0.]])


np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype
array([(0, 0), (0, 0)],
   dtype=[('x', '<i4'), ('y', '<i4')])
Type:   builtin_function_or_method

以上这篇python中numpy.zeros(np.zeros)的使用方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
盘点提高 Python 代码效率的方法
Jul 03 Python
Python中函数的多种格式和使用实例及小技巧
Apr 13 Python
Python实现二叉堆
Feb 03 Python
Python 异常处理的实例详解
Sep 11 Python
Python实现可设置持续运行时间、线程数及时间间隔的多线程异步post请求功能
Jan 11 Python
Python之列表的插入&amp;替换修改方法
Jun 28 Python
pyqt实现.ui文件批量转换为对应.py文件脚本
Jun 19 Python
在PyCharm中实现添加快捷模块
Feb 12 Python
基于django 的orm中非主键自增的实现方式
May 18 Python
Python调用shell cmd方法代码示例解析
Jun 18 Python
从python读取sql的实例方法
Jul 21 Python
Python实现PS滤镜中的USM锐化效果
Dec 04 Python
django项目运行因中文而乱码报错的几种情况解决
Nov 07 #Python
Python创建二维数组实例(关于list的一个小坑)
Nov 07 #Python
python 简单备份文件脚本v1.0的实例
Nov 06 #Python
Python如何实现MySQL实例初始化详解
Nov 06 #Python
django rest framework之请求与响应(详解)
Nov 06 #Python
基于python中的TCP及UDP(详解)
Nov 06 #Python
利用Python循环(包括while&amp;for)各种打印九九乘法表的实例
Nov 06 #Python
You might like
php调用C代码的实现方法
2014/03/11 PHP
yii框架builder、update、delete使用方法
2014/04/30 PHP
PHP中的日期加减方法示例
2014/08/21 PHP
PHP实现的简单组词算法示例
2018/04/10 PHP
jquery中输入验证中一个不错的效果
2010/08/21 Javascript
jQuery与getJson结合的用法实例
2015/08/07 Javascript
Angular.js回顾ng-app和ng-model使用技巧
2016/04/26 Javascript
jquery动态切换背景图片的简单实现方法
2016/05/14 Javascript
Javascript将双字节字符转换成单字节字符并计算长度
2016/06/22 Javascript
JavaScript限制在客户区可见范围的拖拽(解决scrollLeft和scrollTop的问题)(2)
2017/05/17 Javascript
vuejs点击class变化的实例
2018/09/05 Javascript
Koa从零搭建到Api实现项目的搭建方法
2019/07/30 Javascript
JavaScript实现图片伪异步上传过程解析
2020/04/10 Javascript
js实现金山打字通小游戏
2020/07/24 Javascript
如何利用javascript接收json信息并进行处理
2020/08/06 Javascript
基于进程内通讯的python聊天室实现方法
2015/06/28 Python
Django Highcharts制作图表
2016/08/27 Python
对python使用telnet实现弱密码登录的方法详解
2019/01/26 Python
Python 实现一个手机号码获取妹子名字的功能
2019/09/25 Python
关于Pytorch MaxUnpool2d中size操作方式
2020/01/03 Python
Tensorflow分批量读取数据教程
2020/02/07 Python
Python AutoCAD 系统设置的实现方法
2020/04/01 Python
Python 测试框架unittest和pytest的优劣
2020/09/26 Python
《姥姥的剪纸》教学反思
2014/02/25 职场文书
法制宣传教育方案
2014/05/09 职场文书
新教师培训心得体会
2014/09/02 职场文书
镇班子对照检查材料思想汇报
2014/09/24 职场文书
2014幼儿园班主任工作总结
2014/12/04 职场文书
幼儿园个人总结
2015/02/28 职场文书
妈妈再爱我一次观后感
2015/06/08 职场文书
现实表现证明材料
2015/06/19 职场文书
公司考勤管理制度
2015/08/04 职场文书
小学校园广播稿
2015/08/18 职场文书
vue使用v-model进行跨组件绑定的基本实现方法
2021/04/28 Vue.js
直播实况, OMG破敌三路五十分钟大战神技局摩托车
2022/04/01 DOTA
td 内容自动换行 table表格td设置宽度后文字太多自动换行
2022/12/24 HTML / CSS