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之入门(五)缩进和选择
May 27 Python
Python中输出ASCII大文字、艺术字、字符字小技巧
Apr 28 Python
python使用urllib2实现发送带cookie的请求
Apr 28 Python
Python基于checksum计算文件是否相同的方法
Jul 09 Python
Python的Django中将文件上传至七牛云存储的代码分享
Jun 03 Python
解决python os.mkdir创建目录失败的问题
Oct 16 Python
python 处理string到hex脚本的方法
Oct 26 Python
Python 的字典(Dict)是如何存储的
Jul 05 Python
详细整理python 字符串(str)与列表(list)以及数组(array)之间的转换方法
Aug 30 Python
Python3爬虫中Selenium的用法详解
Jul 10 Python
Python大批量搜索引擎图像爬虫工具详解
Nov 16 Python
python 开心网和豆瓣日记爬取的小爬虫
May 29 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将XML转数组过程详解
2013/11/13 PHP
CakePHP框架Model函数定义方法示例
2017/08/04 PHP
php命名空间设计思想、用法与缺点分析
2019/07/17 PHP
firefox和IE系列的相关区别整理 以备后用
2009/12/28 Javascript
jquery插件格式实例分析
2016/06/16 Javascript
Angular.js之作用域scope'@','=','&amp;'实例详解
2017/02/28 Javascript
在vue中实现点击选择框阻止弹出层消失的方法
2018/09/15 Javascript
Angular4 Select选择改变事件的方法
2018/10/09 Javascript
通过实例了解js函数中参数的传递
2019/06/15 Javascript
vue项目中监听手机物理返回键的实现
2020/01/18 Javascript
解决node终端下运行js文件不支持ES6语法
2020/04/04 Javascript
如何正确解决VuePress本地访问出现资源报错404的问题
2020/12/03 Vue.js
Python制作Windows系统服务
2017/03/25 Python
Python使用pymysql小技巧
2017/06/04 Python
Python操作Redis之设置key的过期时间实例代码
2018/01/25 Python
详解python的ORM中Pony用法
2018/02/09 Python
Python单元测试实例详解
2018/05/25 Python
python tkinter实现屏保程序
2019/07/30 Python
如何通过Django使用本地css/js文件
2020/01/20 Python
python字典和json.dumps()的遇到的坑分析
2020/03/11 Python
Python单元测试及unittest框架用法实例解析
2020/07/09 Python
教你如何用python操作摄像头以及对视频流的处理
2020/10/12 Python
python 元组和列表的区别
2020/12/30 Python
CSS3中的@keyframes关键帧动画的选择器绑定
2016/06/13 HTML / CSS
HTML5的结构和语义(4):语义性的内联元素
2008/10/17 HTML / CSS
html2canvas生成的图片偏移不完整的解决方法
2020/05/19 HTML / CSS
医疗保健专业人士购物网站:Scrubs & Beyond
2017/02/08 全球购物
Hoover胡佛官网:美国吸尘器和洗地机品牌
2019/01/09 全球购物
REN Clean Skincare官网:英国本土有机护肤品牌
2019/02/23 全球购物
Tessabit日本:集世界奢侈品和设计师品牌的意大利精品买手店
2020/01/07 全球购物
绿色家庭事迹材料
2014/05/01 职场文书
2016春季幼儿园大班开学寄语
2015/12/03 职场文书
python 机器学习的标准化、归一化、正则化、离散化和白化
2021/04/16 Python
python基础之错误和异常处理
2021/10/24 Python
如何在Python中妥善使用进度条详解
2022/04/05 Python
MySQL数据库配置信息查看与修改方法详解
2022/06/25 MySQL