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

目录
打赏
0
0
0
0
5
分享
相关文章
数据科学:Numpy、Pandas、Matplotlib学习(更新ing...)
数据科学:Numpy、Pandas、Matplotlib学习(更新ing...)
105 0
NumPy 数组学习手册:6~7
NumPy 数组学习手册:6~7
75 0
AttributeError: module ‘numpy‘ has no attribute ‘array‘解决办法
AttributeError: module ‘numpy‘ has no attribute ‘array‘解决办法
916 0
|
5月前
|
Numpy学习笔记(一):array()、range()、arange()用法
这篇文章是关于NumPy库中array()、range()和arange()函数的用法和区别的介绍。
164 6
Numpy学习笔记(一):array()、range()、arange()用法
|
10月前
|
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()`。矩阵运算包括加减乘、转置、逆矩阵等。
103 2
python学习——NumPy数值计算基础
ArrayList集合常用方法,.set可以用来生成图片和赋值命名,array.remove(1),array.set(1,“xxxx”)可以修改指定位置,array.size可以获取元素的个数
ArrayList集合常用方法,.set可以用来生成图片和赋值命名,array.remove(1),array.set(1,“xxxx”)可以修改指定位置,array.size可以获取元素的个数
NumPy数组运算:元素级与广播机制剖析
【4月更文挑战第17天】NumPy是Python数值计算库,提供元素级运算和广播机制。元素级运算针对数组每个元素单独计算,如加法、减法等;广播机制允许不同形状数组间运算,通过扩展小数组形状匹配大数组。了解这两点能帮助更好地运用NumPy进行数值计算和数据处理。
<foreach>元素中collection=list改成collection=array
<foreach>元素中collection=list改成collection=array
NumPy 数组学习手册:1~5
NumPy 数组学习手册:1~5
114 0

热门文章

最新文章