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实现获取某天是某个月中的第几周
Feb 11 Python
python登录pop3邮件服务器接收邮件的方法
Apr 30 Python
python比较两个列表是否相等的方法
Jul 28 Python
详解如何使用Python编写vim插件
Nov 28 Python
python生成圆形图片的方法
Mar 25 Python
TensorFlow实现卷积神经网络CNN
Mar 09 Python
python 含子图的gif生成时内存溢出的方法
Jul 07 Python
Python bytes string相互转换过程解析
Mar 05 Python
python GUI库图形界面开发之PyQt5信号与槽多窗口数据传递详细使用方法与实例
Mar 08 Python
python+excel接口自动化获取token并作为请求参数进行传参操作
Nov 10 Python
Python用摘要算法生成token及检验token的示例代码
Dec 01 Python
Python扫描端口的实现
Jan 25 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
浅谈htmlentities 、htmlspecialchars、addslashes的使用方法
2016/12/09 PHP
tp框架(thinkPHP)实现三次登陆密码错误之后锁定账号功能示例
2018/05/24 PHP
javascript 学习笔记(一)DOM基本操作
2011/04/08 Javascript
js中设置元素class的三种方法小结
2011/08/28 Javascript
jquery中常用的SET和GET$(”#msg”).html循环介绍
2013/10/09 Javascript
node.js中的path.resolve方法使用说明
2014/12/08 Javascript
浅谈JavaScript事件的属性列表
2015/03/01 Javascript
js实现时间显示几天前、几小时前或者几分钟前的方法集锦
2015/05/29 Javascript
html5+javascript实现简单上传的注意细节
2016/04/18 Javascript
基于JSONP原理解析(推荐)
2017/12/04 Javascript
jQuery使用bind动态绑定事件无效的处理方法
2018/12/11 jQuery
小程序实现短信登录倒计时
2019/07/12 Javascript
封装一下vue中的axios示例代码详解
2020/02/16 Javascript
vue搜索页开发实例代码详解(热门搜索,历史搜索,淘宝接口演示)
2020/04/11 Javascript
如何在vue-cli中使用css-loader实现css module
2021/01/07 Vue.js
[01:14]2019完美世界城市挑战赛(秋季赛)全国总决赛精彩花絮
2020/01/08 DOTA
Python字符串替换实例分析
2015/05/11 Python
浅谈Python的异常处理
2016/06/19 Python
Python 在字符串中加入变量的实例讲解
2018/05/02 Python
Python字符串的一些操作方法总结
2019/06/10 Python
Python logging设置和logger解析
2019/08/28 Python
python中数字是否为可变类型
2020/07/08 Python
python开发入门——列表生成式
2020/09/03 Python
HTML5中外部浏览器唤起微信分享
2020/01/02 HTML / CSS
Myprotein蛋白粉美国官网:欧洲畅销运动营养品牌
2016/11/15 全球购物
Lyle & Scott苏格兰金鹰官网:英国皇室御用品牌
2018/05/09 全球购物
美国领先的在线邮轮旅游公司:CruiseDirect
2018/06/07 全球购物
幼教个人求职信范文
2013/12/02 职场文书
家长给幼儿园的表扬信
2014/01/09 职场文书
家长给老师的道歉信
2014/01/13 职场文书
大学军训感言200字
2014/02/26 职场文书
技术总监管理职责范本
2014/03/06 职场文书
钱塘江大潮导游词
2015/02/03 职场文书
幼儿园庆元旦主持词
2015/07/06 职场文书
《风筝》教学反思
2016/02/23 职场文书
python实战之用emoji表情生成文字
2021/05/08 Python