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中Genarator函数用法分析
Apr 08 Python
python 第三方库的安装及pip的使用详解
May 11 Python
Python 爬虫图片简单实现
Jun 01 Python
python实现稀疏矩阵示例代码
Jun 09 Python
python将unicode转为str的方法
Jun 21 Python
python删除服务器文件代码示例
Feb 09 Python
Python3导入自定义模块的三种方法详解
Apr 13 Python
Python基于whois模块简单识别网站域名及所有者的方法
Apr 23 Python
python 内置函数汇总详解
Sep 16 Python
python中对_init_的理解及实例解析
Oct 11 Python
python实现身份证实名认证的方法实例
Nov 08 Python
新建文件时Pycharm中自动设置头部模板信息的方法
Apr 17 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 array_multisort函数 对数据库结果进行复杂排序
2013/06/08 PHP
几个优化WordPress中JavaScript加载体验的插件介绍
2015/12/17 PHP
TP5框架model常见操作示例小结【增删改查、聚合、时间戳、软删除等】
2020/04/05 PHP
javascript 验证日期的函数
2010/03/18 Javascript
关于onchange事件在IE和FF下的表现及解决方法
2014/03/08 Javascript
javascript表单事件处理方法详解
2016/05/15 Javascript
JavaScript实现实时更新系统时间的实例代码
2017/04/04 Javascript
Vue filter介绍及详细使用
2018/04/04 Javascript
使用Vue如何写一个双向数据绑定(面试常见)
2018/04/20 Javascript
如何为vue的项目添加单元测试
2018/12/19 Javascript
javascript实现商品图片放大镜
2019/11/28 Javascript
Vue3新特性之在Composition API中使用CSS Modules
2020/07/13 Javascript
vue递归获取父元素的元素实例
2020/08/07 Javascript
JS JQuery获取data-*属性值方法解析
2020/09/01 jQuery
vue下载二进制流图片操作
2020/10/26 Javascript
[59:44]2018DOTA2亚洲邀请赛 3.31 小组赛 B组 paiN vs iG
2018/03/31 DOTA
[42:11]TNC vs Pain 2018国际邀请赛小组赛BO2 第二场 8.17
2018/08/20 DOTA
Python中函数的多种格式和使用实例及小技巧
2015/04/13 Python
Python 文件管理实例详解
2015/11/10 Python
python实现按首字母分类查找功能
2019/10/31 Python
django自带的权限管理Permission用法说明
2020/05/13 Python
英国领先的男士服装和时尚零售商:Burton
2017/01/09 全球购物
网络、C以及其他硬件方面的面试题
2016/08/23 面试题
abstract 可以和 virtual 一起使用吗?可以和 override 一起使用吗?
2012/10/15 面试题
机械工程师的岗位职责
2013/11/17 职场文书
应届毕业生如何写求职信
2014/02/16 职场文书
企业节能减排实施方案
2014/03/19 职场文书
《画》教学反思
2014/04/14 职场文书
教师敬业奉献模范事迹材料
2014/05/18 职场文书
新农村建设典型材料
2014/05/31 职场文书
学术会议通知范文
2015/04/15 职场文书
2016大学军训心得体会
2016/01/11 职场文书
2016开学第一课心得体会
2016/01/23 职场文书
2019学校运动会开幕词
2019/05/13 职场文书
SqlServer: 如何更改表的文件组?(进而改变存储位置)
2021/04/05 SQL Server
SQL Server数据库查询出现阻塞之性能调优
2022/04/10 SQL Server