Numpy: zeros_like函数

作者: ACphart | 来源:发表于2018-08-23 21:41 被阅读14次

  • numpy.zeros_like(a)a是一个ndarray,翻译过来应该数组更容易理解一点吧。

先上代码

In  [1]: a = np.arange(24).reshape(4,6)
...      a_0 = np.zeros_like(a)
...      a.shape
...      a_0.shape
...      a_0
Out [1]: (4, 6)
Out [1]: (4, 6)
Out [1]: array([[0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0]])  

注:对于上面代码中如何输出多个变量有疑惑的话可以看一下我的另一篇文章IPython中输出多个变量

  • 顾名思义这个函数的意思就是生成一个和你所给数组a相同shape的全0数组。

相关文章

网友评论

    本文标题:Numpy: zeros_like函数

    本文链接:https://www.haomeiwen.com/subject/psfviftx.html