Return a new tensor with the given shape, and the original tensor is not changed. Args: shape (list ): new shape, which should have the same volumn as the original shape. Returns: new tensor reshaped
(self, shape)
| 230 | return t |
| 231 | |
| 232 | def reshape(self, shape): |
| 233 | '''Return a new tensor with the given shape, and the original |
| 234 | tensor is not changed. |
| 235 | |
| 236 | Args: |
| 237 | shape (list<int>): new shape, which should have the same |
| 238 | volumn as the original shape. |
| 239 | |
| 240 | Returns: |
| 241 | new tensor reshaped |
| 242 | ''' |
| 243 | t = Tensor(self.shape, self.device, self.dtype) |
| 244 | assert product(self.shape) == product(shape), \ |
| 245 | 'product of shape should be equal' |
| 246 | t.shape = shape |
| 247 | t.data = singa.Reshape(self.data, shape) |
| 248 | return t |
| 249 | |
| 250 | def reset_like(self, t): |
| 251 | '''Reset the shape, dtype and device as the given tensor. |