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 09 Python
Python实现文件内容批量追加的方法示例
Aug 29 Python
Python 多进程和数据传递的理解
Oct 09 Python
使用Python写一个小游戏
Apr 02 Python
在Mac上删除自己安装的Python方法
Oct 29 Python
Python面向对象基础入门之编码细节与注意事项
Dec 11 Python
对python tkinter窗口弹出置顶的方法详解
Jun 14 Python
PyQt5 窗口切换与自定义对话框的实例
Jun 20 Python
TensorBoard 计算图的可视化实现
Feb 15 Python
python梯度下降算法的实现
Feb 24 Python
python asyncio 协程库的使用
Jan 21 Python
django使用多个数据库的方法实例
Mar 04 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中json_encode UTF-8中文乱码的更好解决方法
2014/09/28 PHP
PHP中COOKIES使用示例
2015/07/26 PHP
PNGHandler-借助JS让PNG图在IE下实现透明(包括背景图)
2007/08/31 Javascript
js实现一个省市区三级联动选择框代码分享
2013/03/06 Javascript
js抽奖实现随机抽奖代码效果
2013/12/02 Javascript
js控制href内容的连接内容的变化示例
2014/04/30 Javascript
js中的hasOwnProperty和isPrototypeOf方法使用实例
2014/06/06 Javascript
jquery操作select方法汇总
2015/02/05 Javascript
angularJS结合canvas画图例子
2015/02/09 Javascript
使用纯javascript实现经典扫雷游戏
2015/04/23 Javascript
js+cookies实现悬浮购物车的方法
2015/05/25 Javascript
JavaScript 闭包详细介绍
2016/09/28 Javascript
jQuery插件扩展操作入门示例
2017/01/16 Javascript
基于JavaScript实现窗口拖动效果
2017/01/18 Javascript
走进AngularJs之过滤器(filter)详解
2017/02/17 Javascript
footer定位页面底部(代码分享)
2017/03/07 Javascript
jQuery插件zTree实现删除树节点的方法示例
2017/03/08 Javascript
js利用for in循环获取 一个对象的所有属性以及值的实例
2017/03/30 Javascript
关于vuex的学习实践笔记
2017/04/05 Javascript
使用JavaScript实现链表的数据结构的代码
2017/08/02 Javascript
vue父组件向子组件(props)传递数据的方法
2018/01/02 Javascript
实现一个Vue自定义指令懒加载的方法示例
2020/06/04 Javascript
[55:45]LGD vs OG 2019国际邀请赛淘汰赛 胜者组 BO3 第三场 8.24
2019/09/10 DOTA
Python 基础教程之闭包的使用方法
2017/09/29 Python
用tensorflow搭建CNN的方法
2018/03/05 Python
pycharm修改文件的默认打开方式的步骤
2019/07/29 Python
Django实现基于类的分页功能
2019/10/31 Python
使用CSS3实现SVG路径描边动画效果入门教程
2019/10/21 HTML / CSS
详解HTML5表单新增属性
2016/12/21 HTML / CSS
美国豪华时尚女性精品店:Kirna Zabête
2018/01/11 全球购物
正宗的日本零食和糖果订阅盒:Bokksu
2019/11/21 全球购物
德国W家官网,可直邮中国的母婴商城:Windeln.de
2021/03/03 全球购物
普罗米修斯教学反思
2014/02/06 职场文书
升职自荐信怎么写
2015/03/05 职场文书
Go本地测试解耦任务拆解及沟通详解Go本地测试的思路沟通的重要性总结
2022/06/21 Golang
JS前端使用Canvas快速实现手势解锁特效
2022/09/23 Javascript