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写的一个简单监控系统
Jun 19 Python
Python面向对象编程中关于类和方法的学习笔记
Jun 30 Python
Python中int()函数的用法浅析
Oct 17 Python
python实现Floyd算法
Jan 03 Python
Python操作mysql数据库实现增删查改功能的方法
Jan 15 Python
在windows下Python打印彩色字体的方法
May 15 Python
Python爬虫将爬取的图片写入world文档的方法
Nov 07 Python
Python解决pip install时出现的Could not fetch URL问题
Aug 01 Python
python百行代码自制电脑端网速悬浮窗的实现
May 12 Python
python中wheel的用法整理
Jun 15 Python
Python预测2020高考分数和录取情况
Jul 08 Python
Python绘制组合图的示例
Sep 18 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中使用灵巧的体系结构
2006/10/09 PHP
PHP中的生成XML文件的4种方法分享
2012/10/06 PHP
有关PHP性能优化的介绍
2013/06/20 PHP
CodeIgniter输出中文乱码的两种解决办法
2014/06/12 PHP
PHP登录环节防止sql注入的方法浅析
2014/06/30 PHP
js+css实现增加表单可用性之提示文字
2013/06/03 Javascript
file控件选择上传文件确定后触发的js事件是哪个
2014/03/17 Javascript
浅析javascript的间隔调用和延时调用
2014/11/12 Javascript
jQuery的context属性用法实例
2014/12/27 Javascript
Markdown+Bootstrap图片自适应属性详解
2016/05/21 Javascript
如何更好的编写js async函数
2018/05/13 Javascript
Vue.js 利用v-for中的index值实现隔行变色
2018/08/01 Javascript
使用vue.js在页面内组件监听scroll事件的方法
2018/09/11 Javascript
详解angularjs4部署文件过大解决过程
2018/12/05 Javascript
JS实现求5的阶乘示例
2019/01/21 Javascript
微信小程序基础教程之worker线程的使用方法
2019/07/15 Javascript
node爬取新型冠状病毒的疫情实时动态
2020/02/06 Javascript
小程序分享链接onShareAppMessage的具体用法
2020/05/22 Javascript
基于p5.js 2D图像接口的扩展(交互实现)
2020/11/30 Javascript
[17:13]DOTA2 HEROS教学视频教你分分钟做大人-斯拉克
2014/06/13 DOTA
[07:52]2014DOTA2 TI逗比武士游V社解说背后的故事
2014/07/10 DOTA
[01:31:22]Ti4 循环赛第四日附加赛LGD vs Mouz
2014/07/13 DOTA
基于python的七种经典排序算法(推荐)
2016/12/08 Python
Python数据分析:手把手教你用Pandas生成可视化图表的教程
2018/12/15 Python
解决python xlrd无法读取excel文件的问题
2018/12/25 Python
基于OpenCV python3实现证件照换背景的方法
2019/03/22 Python
Python的高阶函数用法实例分析
2019/04/11 Python
Python如何输出警告信息
2020/07/30 Python
美国小蜜蜂Burt’s Bees德国官网:天然唇部、皮肤和身体护理产品
2020/06/14 全球购物
Java中的类包括什么内容?设计时要注意哪些方面
2012/05/23 面试题
新闻专业大学生找工作的自我评价
2013/10/30 职场文书
党的群众路线对照检查材料思想汇报(学校)
2014/10/04 职场文书
资料员岗位职责
2015/02/10 职场文书
党风廉政建设个人总结
2015/03/06 职场文书
MySQL实例精讲单行函数以及字符数学日期流程控制
2021/10/15 MySQL
详解Nginx的超时keeplive_timeout配置步骤
2022/05/25 Servers