python中numpy.zeros(np.zeros)的使用方法
作者:jingxian 发布时间:2023-10-08 17:40:07
标签:python,numpy.zeros,np.zeros
翻译:
用法: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
来源:http://blog.csdn.net/qq_26948675/article/details/54318917


猜你喜欢
- 最近经常看到各平台里都有Python的广告,都是对excel的操作,这里明哥收集整理了一下pandas对excel的操作方法和使用过程。本篇
- '****'函数名称: strReplace(Str)'函数功能: 过滤单引号'参数说明: Str 
- 前言本文继续学习下 Python 编程在网络攻防领域的应用,主要是通过 Python 脚本进行 SSH 登录爆破和 FTP 服务登录爆破。S
- 背景最近在用Electron开发一款应用,其中有涉及到检测因特网是否断开的需求。Electron基于Chromium和Node.js,让你可
- python提供了两个非常重要的功能来处理python程序在运行中出现的异常和错误。你可以使用该功能来调试python程序。1.异常处理:
- 我们先思考一下,如果需要达到自动化接口测试的效果,那么我们在基本的模拟请求上还需要做哪些呢?以下我粗略概括为 3 个问题(欢迎更多补充与建
- 文本框: <input type="text" onkeydown="keydownsearch(eve
- 对于每个类型拥有的值范围以及并且指定日期何时间值的有效格式的描述见7.3.6 日期和时间类型。 这里是一个使用日期函数
- <title>无标题文档</title> <script language="javascript&
- 类的私有属性和方法Python是个开放的语言,默认情况下所有的属性和方法都是公开的 或者叫公有方法,不像C++和 Java中有明确的publ
- 目录logging的简单使用|2logging常见对象|3logging基本使用|4logging之Formatter对象|5logging
- MySQL用户和权限在MySQL中有一个系统自身就带有的数据库叫MySQL,数据库装好以后系统自带了好几个数据库MySQL就是其中过一个,M
- 废话不多说了,先给大家展示下效果图:这是iOS下的效果,android下完全一致。通过do_GestureView组件和do_Animati
- 前言联邦学习(Federated Learning) 是人工智能的一个新的分支,这项技术是谷歌于2016年首次提出,本篇论文第一次描述了这一
- 一、问题引出浅拷贝首先看下面代码的执行情况:a = [1, 2, 3]print('a = %s' % a) # a = [
- 前言现在正是卡塔尔世界杯激战正酣的时候,每天都有各种各样的新闻。而且,不同的球队,随着比赛的进程,关注的热度也会发生翻天覆地的变化。今天我们
- 业务需求 识别验证码图片中的数字信息,用pyt
- 读取列表中字典的value值list = [{"name": "推荐食谱", "1&quo
- 微博热搜的爬取较为简单,我只是用了lxml和requests两个库url= https://s.weibo.com/top/summary?
- 复制代码 代码如下: public partial class CMS_DBDataContext { partial void OnCre