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中__init__.py文件的作用详解
Sep 18 Python
flask使用session保存登录状态及拦截未登录请求代码
Jan 19 Python
python监控键盘输入实例代码
Feb 09 Python
Python中的TCP socket写法示例
May 11 Python
python爬虫之线程池和进程池功能与用法详解
Aug 02 Python
Django框架模板注入操作示例【变量传递到模板】
Dec 19 Python
python设置环境变量的作用和实例
Jul 09 Python
Python流程控制 if else实现解析
Sep 02 Python
python+opencv边缘提取与各函数参数解析
Mar 09 Python
python爬虫容易学吗
Jun 02 Python
Django实现内容缓存实例方法
Jun 30 Python
基于python实现删除指定文件类型
Jul 21 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实现zip文件解压操作
2015/11/03 PHP
编写PHP程序检查字符串中的中文字符个数的实例分享
2016/03/17 PHP
laravel5环境隐藏index.php后缀(apache)的方法
2019/10/12 PHP
Highslide.js是一款基于js实现的网页中图片展示插件
2020/03/30 Javascript
cnblogs csdn 代码运行框实现代码
2009/11/02 Javascript
jqTransform form表单美化插件使用方法
2012/07/05 Javascript
js取两个数组的交集|差集|并集|补集|去重示例代码
2013/08/07 Javascript
JavaScript中的立即执行函数表达式介绍
2015/03/15 Javascript
使用vue.js开发时一些注意事项
2016/04/27 Javascript
js简单正则验证汉字英文及下划线的方法
2016/11/28 Javascript
jQuery Easy UI中根据第一个下拉框选中的值设置第二个下拉框是否可以编辑
2016/11/29 Javascript
实现JavaScript高性能的数据存储
2016/12/11 Javascript
bootstrap+jQuery实现的动态进度条功能示例
2017/05/25 jQuery
js模拟百度模糊搜索的实例
2017/08/04 Javascript
AngularJS实现的根据数量与单价计算总价功能示例
2017/12/26 Javascript
基于Vue的SPA动态修改页面title的方法(推荐)
2018/01/02 Javascript
基于vue v-for 循环复选框-默认勾选第一个的实现方法
2018/03/03 Javascript
JS使用for in有序获取对象数据
2020/05/19 Javascript
python3解析库lxml的安装与基本使用
2018/06/27 Python
Python访问MongoDB,并且转换成Dataframe的方法
2018/10/15 Python
详解Python函数式编程—高阶函数
2019/03/29 Python
Python登录系统界面实现详解
2019/06/25 Python
利用PyCharm操作Github(仓库新建、更新,代码回滚)
2019/12/18 Python
python列表推导和生成器表达式知识点总结
2020/01/10 Python
详解Canvas事件绑定
2018/06/27 HTML / CSS
解决HTML5中的audio在手机端和微信端的不能自动播放问题
2019/11/04 HTML / CSS
Baby Tulai澳大利亚:美国婴儿背带品牌
2018/10/15 全球购物
中专生的个人自我评价
2013/12/11 职场文书
采购助理岗位职责
2014/02/16 职场文书
《火烧云》教学反思
2014/04/12 职场文书
信访工作经验交流材料
2014/05/23 职场文书
课程设计的心得体会
2014/09/03 职场文书
教师党员先进性教育自我剖析材料思想汇报
2014/09/24 职场文书
教师党员自我评价2015
2015/03/04 职场文书
个人简历自我评价怎么写
2015/03/10 职场文书
怎样写好工作计划
2019/04/10 职场文书