diff --git a/imperative/python/megengine/core/tensor/tensor_wrapper.py b/imperative/python/megengine/core/tensor/tensor_wrapper.py index 05f2d7091f187e9f3993f1d6f5e79ac56a6fd018..840dfcab99c54b171574ba63133894313c853370 100644 --- a/imperative/python/megengine/core/tensor/tensor_wrapper.py +++ b/imperative/python/megengine/core/tensor/tensor_wrapper.py @@ -371,7 +371,7 @@ class ArrayMethodMixin(abc.ABC): def transpose(self, *args): if not args: - args = reversed(range(self.ndim)) + args = range(self.ndim)[::-1] return _transpose(self, _expand_args(args)) def flatten(self): diff --git a/imperative/python/test/unit/core/test_tensor_wrapper.py b/imperative/python/test/unit/core/test_tensor_wrapper.py index 26bc9c9c3f24afa21ea8ff2e2f254925454b9583..a90b109a4014790d98ab0c5e208508859bea8bd5 100644 --- a/imperative/python/test/unit/core/test_tensor_wrapper.py +++ b/imperative/python/test/unit/core/test_tensor_wrapper.py @@ -60,3 +60,9 @@ def test_computing_with_numpy_array(): np.testing.assert_equal(np.add(xx, y).numpy(), np.add(x, y)) np.testing.assert_equal(np.equal(xx, y).numpy(), np.equal(x, y)) np.testing.assert_equal(np.equal(xx, xx).numpy(), np.equal(x, x)) + + +def test_transpose(): + x = np.random.rand(2, 5).astype("float32") + xx = TensorWrapper(x) + np.testing.assert_almost_equal(xx.T.numpy(), x.T)