numpy.expand

您所在的位置:网站首页 rgb2ycbcr函数解释 numpy.expand

numpy.expand

2024-05-26 16:22| 来源: 网络整理| 查看: 265

扩展数组的形状。

插入一个新轴,该轴将出现在展开的数组形状中的 axis 位置。

Parameters aarray_like

Input array.

axisint 或整数元组

在扩展轴中放置新轴(或多个轴)的位置。

自版本 1.13.0 起已弃用:传递 axis > a.ndim 的轴将被视为 axis == a.ndim ,传递 axis < -a.ndim - 1 将被视为 axis == 0 。此行为已被弃用。

版本 1.18.0 中进行了更改:现在支持轴元组。现在禁止如上所述的超出范围的轴并引发 AxisError 。

Returns resultndarray

a 视图,尺寸数量增加。

See also

squeeze

逆操作,删除单一维度

reshape

插入、删除和组合尺寸,以及调整现有尺寸的大小

doc.indexing 、 atleast_1d 、 atleast_2d 、 atleast_3d Examples >>> x = np.array([1, 2]) >>> x.shape (2,)

以下相当于 x[np.newaxis, :] 或 x[np.newaxis] :

>>> y = np.expand_dims(x, axis=0) >>> y array([[1, 2]]) >>> y.shape (1, 2)

以下相当于 x[:, np.newaxis] :

>>> y = np.expand_dims(x, axis=1) >>> y array([[1], [2]]) >>> y.shape (2, 1)

axis 也可能是一个元组:

>>> y = np.expand_dims(x, axis=(0, 1)) >>> y array([[[1, 2]]]) >>> y = np.expand_dims(x, axis=(2, 0)) >>> y array([[[1], [2]]])

请注意,某些示例可能使用 None 而不是 np.newaxis 。这些是相同的对象:

>>> np.newaxis is None True


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3