用法:
reshape(*shape, **kwargs)
- shape:(
tuple of int
, or
n ints
) -新形状不应更改数组大小,即np.prod(new_shape)
应等于np.prod(self.shape)
。形状的某些维度可以从集合 {0, -1, -2, -3, -4} 中获取特殊值。每一个的意义解释如下:0
将此维度从输入复制到输出形状。 例子:- input shape = (2,3,4), shape = (4,0,2), output shape = (4,3,2) - input shape = (2,3,4), shape = (2,0,0), output shape = (2,3,4)
-1
通过使用输入维度的剩余部分来推断输出形状的维度,保持新数组的大小与输入数组的大小相同。最多一维形状可以是-1。 例子:- input shape = (2,3,4), shape = (6,1,-1), output shape = (6,1,4) - input shape = (2,3,4), shape = (3,-1,8), output shape = (3,1,8) - input shape = (2,3,4), shape=(-1,), output shape = (24,)
-2
将输入尺寸的所有/剩余部分复制到输出形状。 例子:- input shape = (2,3,4), shape = (-2,), output shape = (2,3,4) - input shape = (2,3,4), shape = (2,-2), output shape = (2,3,4) - input shape = (2,3,4), shape = (-2,1,1), output shape = (2,3,4,1,1)
-3
使用输入形状的两个连续维度的乘积作为输出维度。 例子:- input shape = (2,3,4), shape = (-3,4), output shape = (6,4) - input shape = (2,3,4,5), shape = (-3,-3), output shape = (6,20) - input shape = (2,3,4), shape = (0,-3), output shape = (2,12) - input shape = (2,3,4), shape = (-3,-2), output shape = (6,4)
-4
将输入的一维拆分为在形状 -4 之后传递的二维(可以包含 -1)。 例子:- input shape = (2,3,4), shape = (-4,1,2,-2), output shape =(1,2,3,4) - input shape = (2,3,4), shape = (2,-4,-1,3,-2), output shape = (2,1,3,4)
- 如果参数
reverse
设置为 1,则从右到左推断特殊值。 例子:- without reverse=1, for input shape = (10,5,4), shape = (-1,0), output shape would be (40,5). - with reverse=1, output shape will be (50,4).
- reverse:(
bool
,
default False
) - 如果为 true,则从右到左推断特殊值。仅支持作为关键字参数。
- shape:(
具有所需形状的数组,与该数组共享数据。
参数:
返回:
返回类型:
返回一个看法在不改变任何数据的情况下,使用新形状的这个数组。
例子:
>>> x = mx.nd.arange(0,6).reshape(2,3) >>> x.asnumpy() array([[ 0., 1., 2.], [ 3., 4., 5.]], dtype=float32) >>> y = x.reshape(3,2) >>> y.asnumpy() array([[ 0., 1.], [ 2., 3.], [ 4., 5.]], dtype=float32) >>> y = x.reshape(3,-1) >>> y.asnumpy() array([[ 0., 1.], [ 2., 3.], [ 4., 5.]], dtype=float32) >>> y = x.reshape(3,2) >>> y.asnumpy() array([[ 0., 1.], [ 2., 3.], [ 4., 5.]], dtype=float32) >>> y = x.reshape(-3) >>> y.asnumpy() array([ 0. 1. 2. 3. 4. 5.], dtype=float32) >>> y[:] = -1 >>> x.asnumpy() array([[-1., -1., -1.], [-1., -1., -1.]], dtype=float32)
相关用法
- Python mxnet.ndarray.sparse.BaseSparseNDArray.astype用法及代码示例
- Python mxnet.ndarray.sparse.BaseSparseNDArray.size用法及代码示例
- Python mxnet.ndarray.sparse.trunc用法及代码示例
- Python mxnet.ndarray.sparse.row_sparse_array用法及代码示例
- Python mxnet.ndarray.sparse.broadcast_mul用法及代码示例
- Python mxnet.ndarray.sparse.rsqrt用法及代码示例
- Python mxnet.ndarray.sparse.sgd_update用法及代码示例
- Python mxnet.ndarray.sparse.broadcast_plus用法及代码示例
- Python mxnet.ndarray.sparse.rint用法及代码示例
- Python mxnet.ndarray.sparse.RowSparseNDArray用法及代码示例
- Python mxnet.ndarray.sparse.sign用法及代码示例
- Python mxnet.ndarray.sparse.concat用法及代码示例
- Python mxnet.ndarray.sparse.make_loss用法及代码示例
- Python mxnet.ndarray.sparse.adagrad_update用法及代码示例
- Python mxnet.ndarray.sparse.exp用法及代码示例
- Python mxnet.ndarray.sparse.square用法及代码示例
- Python mxnet.ndarray.sparse.clip用法及代码示例
- Python mxnet.ndarray.sparse.retain用法及代码示例
- Python mxnet.ndarray.sparse.round用法及代码示例
- Python mxnet.ndarray.sparse.zeros_like用法及代码示例
注:本文由纯净天空筛选整理自apache.org大神的英文原创作品 mxnet.ndarray.sparse.BaseSparseNDArray.reshape。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。