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的Treq on Twisted来进行HTTP压力测试
Apr 16 Python
简单介绍Python中的try和finally和with方法
May 05 Python
Django中使用group_by的方法
May 26 Python
python socket多线程通讯实例分析(聊天室)
Apr 06 Python
Python3 JSON编码解码方法详解
Sep 06 Python
Pytorch在NLP中的简单应用详解
Jan 08 Python
TensorFlow的reshape操作 tf.reshape的实现
Apr 19 Python
PyInstaller运行原理及常用操作详解
Jun 13 Python
基于python实现判断字符串是否数字算法
Jul 10 Python
高考考python编程是真的吗
Jul 20 Python
python 爬取华为应用市场评论
May 29 Python
Python序列化模块JSON与Pickle
Jun 05 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 301转向实现代码
2008/09/18 PHP
php 生成随机验证码图片代码
2010/02/08 PHP
PHP中cookie和session的区别实例分析
2014/08/28 PHP
详解php比较操作符的安全问题
2015/12/03 PHP
PHP架构及原理知识点详解
2019/12/22 PHP
JavaScript 函数式编程的原理
2009/10/16 Javascript
jquery 实现表单验证功能代码(简洁)
2012/07/03 Javascript
JS跨域代码片段
2012/08/30 Javascript
原生javaScript做得动态表格(注释写的很清楚)
2013/12/29 Javascript
JavaScript中提前声明变量或函数例子
2014/11/12 Javascript
javascript正则表达式之search()用法实例
2015/01/19 Javascript
jquery实现简易的移动端验证表单
2015/11/08 Javascript
JS经典正则表达式笔试题汇总
2016/12/15 Javascript
整理一些最近经常遇到的前端面试题
2017/04/25 Javascript
详解Vue中过度动画效果应用
2017/05/25 Javascript
解决vue中对象属性改变视图不更新的问题
2018/02/23 Javascript
react 实现页面代码分割、按需加载的方法
2018/04/03 Javascript
了解javascript中的Dom操作
2019/05/27 Javascript
python 正则表达式 概述及常用字符
2009/05/04 Python
Python工程师面试题 与Python基础语法相关
2016/01/14 Python
利用 python 对目录下的文件进行过滤删除
2017/12/27 Python
Windows下PyCharm安装图文教程
2018/08/27 Python
python实现机器学习之元线性回归
2018/09/06 Python
Python操作rabbitMQ的示例代码
2019/03/19 Python
对Django 中request.get和request.post的区别详解
2019/08/12 Python
python图形界面开发之wxPython树控件使用方法详解
2020/02/24 Python
HTML5实时语音通话聊天MP3压缩传输3KB每秒
2019/08/28 HTML / CSS
德国著名廉价网上药店:Shop-Apotheke
2017/07/23 全球购物
美国婴儿和儿童服装购物网站:PatPat
2020/10/01 全球购物
大三在校生电子商务求职信
2013/10/29 职场文书
优秀本科毕业生自荐信
2014/07/04 职场文书
2014年党员干部四风问题自我剖析材料
2014/09/29 职场文书
清明节扫墓活动总结
2015/02/09 职场文书
自我评价优缺点范文
2015/03/11 职场文书
《全神贯注》教学反思
2016/02/22 职场文书
weblogic服务建立数据源连接测试更新mysql驱动包的问题及解决方法
2022/01/22 MySQL