python中numpy.zeros(np.zeros)的使用方法

作者:jingxian 时间:2023-10-08 17:40:07 

翻译:

用法: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,numpy.zeros,np.zeros
0
投稿

猜你喜欢

  • 使用Python脚本将绝对url替换为相对url的教程

    2022-09-03 09:36:39
  • Pycharm配置Anaconda环境的详细图文教程

    2021-10-30 00:57:23
  • 分步启动数据库以重命名数据文件

    2009-03-25 12:33:00
  • vue 图片裁剪上传组件的实现

    2024-05-09 15:14:02
  • Apache POI操作批量导入MySQL数据库

    2024-01-27 16:52:58
  • Python基础教程之循环语句(for、while和嵌套循环)

    2022-07-30 10:00:26
  • python同时给两个收件人发送邮件的方法

    2021-10-23 07:31:36
  • 再论Javascript下字符串连接的性能

    2010-06-26 13:13:00
  • Python实现自定义Jupyter魔法命令

    2022-03-10 11:47:04
  • TensorFlow如何指定GPU训练模型

    2022-05-31 10:03:21
  • face++与python实现人脸识别签到(考勤)功能

    2021-10-18 09:06:06
  • Django 使用easy_thumbnails压缩上传的图片方法

    2023-11-10 07:47:38
  • 用ASP实现IE地址栏参数的判断

    2008-10-10 15:54:00
  • 详解Python中Addict模块的使用方法

    2021-11-04 00:06:04
  • ASP网站程序自动升级实现的方法

    2008-10-15 14:28:00
  • discuz 2.0整合asp系统,用户添加函数

    2011-04-02 11:08:00
  • 发个选星星打分/投票功能函数

    2008-05-22 12:38:00
  • 如何通过python实现IOU计算代码实例

    2021-07-09 02:06:44
  • Python中的Numpy 面向数组编程常见操作

    2021-08-21 20:31:32
  • 如何基于python操作json文件获取内容

    2023-03-30 15:48:04
  • asp之家 网络编程 m.aspxhome.com