numpy重新学习系列(5)---如何用np.zeros_like创建一个新的和原来array形状一样的,但是元素为0的新的array

简介: numpy重新学习系列(5)---如何用np.zeros_like创建一个新的和原来array形状一样的,但是元素为0的新的array
'''
numpy.zeros_like
numpy.zeros_like(a, dtype=None, order='K', subok=True, shape=None)[source]
Return an array of zeros with the same shape and type as a given array.
Parameters
a   array_like
    The shape and data-type of a define these same attributes of the returned array.
dtype  data-type, optional
       Overrides the data type of the result.
       New in version 1.6.0.
order   {‘C’, ‘F’, ‘A’, or ‘K’}, optional
        Overrides the memory layout of the result. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a as closely as possible.
       New in version 1.6.0.
subok   bool, optional.
       If True, then the newly created array will use the sub-class type of ‘a’, otherwise it will be a base-class array. Defaults to True.
shape   int or sequence of ints, optional.
       Overrides the shape of the result. If order=’K’ and the number of dimensions is unchanged, will try to keep order, otherwise, order=’C’ is implied.
       New in version 1.17.0.
Returns
out   ndarray
      Array of zeros with the same shape and type as a.
'''
# np.zeros_like的作用
# 很明显,使用np.zeros_like是想要创造一个和目标的array一样的形状结构,但是元素是0的新的array
# 五个参数,一个必须的参数,四个可选的参数
# 第一个参数:a
# 这是一个array数据类型,想要返回和这个array一样的形状、类型的array,即目标array
# 第二个参数:dtype
# 数据类型:重新改变目标array的元素里面的数据类型
# 第三个参数:order
#  这个参数可以改变结果的内存分布。C代表着C语言类型的,F代表Fortan语言类型,
# A代表着原来如果是F连接类型,就还是F,否则就是C类型;K代表着返回和a尽可能相似的结果
# 第四个参数:subok
# 默认是真的。如果是真的,返回的新的array是目标array的一个子类;否则就是基础类。
# 第五个参数:shape
#  改写结果的形状。如果order="K",并且维数没有改变,就保持原来的;否则,order就假定为“C”
# 这就是一个必要参数和四个可选参数的介绍。    

2019102820120953.png

目录
相关文章
|
30天前
|
数据采集 机器学习/深度学习 数据可视化
深入学习NumPy库在数据分析中的应用场景
深入学习NumPy库在数据分析中的应用场景
|
30天前
|
存储 算法 数据挖掘
NumPy 数组学习手册:6~7
NumPy 数组学习手册:6~7
44 0
|
7月前
|
索引 Python
数据科学:Numpy、Pandas、Matplotlib学习(更新ing...)
数据科学:Numpy、Pandas、Matplotlib学习(更新ing...)
68 0
|
9月前
|
数据处理 Python
AttributeError: module ‘numpy‘ has no attribute ‘array‘解决办法
AttributeError: module ‘numpy‘ has no attribute ‘array‘解决办法
515 0
|
9月前
|
机器学习/深度学习 数据处理 C语言
numpy通用函数:快速的逐元素数组函数
numpy通用函数:快速的逐元素数组函数
numpy通用函数:快速的逐元素数组函数
|
9月前
|
测试技术 C++ 索引
【NumPy 数组副本 vs 视图、NumPy 数组形状、重塑、迭代】
【NumPy 数组副本 vs 视图、NumPy 数组形状、重塑、迭代】
|
18天前
|
存储 索引 Python
python学习——NumPy数值计算基础
NumPy基础知识概览:涉及nan(非数字)和inf(无穷)的概念,nan在文件读取或不适当计算时出现,inf在除0操作中出现。数组操作有深拷贝(a=b.copy())、浅拷贝(a=b[:])和引用(a=b)。创建数组方式多样,如`np.array()`、`np.arange()`等。数据类型转换如`np.float64()`、`np.int8()`。随机数生成包含均匀分布、正态分布等。数组索引和切片支持多维操作。改变数组形状用`reshape()`,展平用`ravel()`和`flatten()`。矩阵运算包括加减乘、转置、逆矩阵等。
34 2
python学习——NumPy数值计算基础
|
30天前
|
存储 数据处理 Python
NumPy数组运算:元素级与广播机制剖析
【4月更文挑战第17天】NumPy是Python数值计算库,提供元素级运算和广播机制。元素级运算针对数组每个元素单独计算,如加法、减法等;广播机制允许不同形状数组间运算,通过扩展小数组形状匹配大数组。了解这两点能帮助更好地运用NumPy进行数值计算和数据处理。
|
30天前
|
存储 索引 Python
深入解析NumPy数组的形状与重塑
【4月更文挑战第17天】本文深入解析了NumPy数组的形状和重塑。数组形状是表示数组维度和大小的元组,可通过`shape`属性获取。重塑允许改变数组形状而不改数据,需保证元素总数不变。`reshape`方法用于重塑,其中`-1`可让NumPy自动计算尺寸。注意重塑遵循元素总数相等、仅一次`-1`、内存存储顺序及返回新数组的原则。理解和掌握这些概念对高效使用NumPy处理多维数组至关重要。
|
30天前
|
存储 数据挖掘 Linux
NumPy 数组学习手册:1~5
NumPy 数组学习手册:1~5
41 0