giagrad.Tensor.reshape#
- Tensor.reshape(*newshape) Tensor [source]#
Returns a new tensor with shape equals
newshape
.When possible, the returned tensor will be a view of the input. Otherwise, it will be a copy. Contiguous inputs and inputs with compatible strides can be reshaped without copying, but you should not depend on the copying vs. viewing behavior.
- Parameters:
*newshape¶ (list of ints) – The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
Examples
>>> a = Tensor.empty(6).ones() >>> a.reshape(2, 3) tensor: [[1. 1. 1.] [1. 1. 1.]] fn: Reshape >>> b = Tensor.empty(2, 2, 2).zeros() >>> b.reshape(2, -1) tensor: [[0. 0. 0. 0.] [0. 0. 0. 0.]] fn: Reshape