Skip to content

Commit 430c94e

Browse files
committed
Q2
1 parent 68f1f00 commit 430c94e

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

questions/2_transpose-of-a-matrix/tinygrad/solution.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
def transpose_matrix_tg(a) -> Tensor:
44
"""
55
Transpose a 2D matrix `a` using tinygrad.
6-
Inputs can be Python lists, NumPy arrays, or tinygrad Tensors.
6+
Inputs are tinygrad Tensors.
77
Returns a transposed Tensor.
88
"""
9-
a_t = Tensor(a)
10-
return a_t.transpose(0,1)
9+
return a.T
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
from tinygrad.tensor import Tensor
22

3-
def transpose_matrix_tg(a) -> Tensor:
3+
def transpose_matrix_tg(a:Tensor) -> Tensor:
44
"""
55
Transpose a 2D matrix `a` using tinygrad.
6-
Inputs can be Python lists, NumPy arrays, or tinygrad Tensors.
6+
Inputs are tinygrad Tensors.
77
Returns a transposed Tensor.
88
"""
9-
# Convert to Tensor
10-
a_t = Tensor(a)
11-
# Your implementation here
129
pass
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[
22
{
3-
"test": "from tinygrad.tensor import Tensor\nres = transpose_matrix_tg([[1,2,3],[4,5,6]])\nprint(res.numpy().tolist())",
3+
"test": "from tinygrad.tensor import Tensor\nres = transpose_matrix_tg(Tensor([[1,2,3],[4,5,6]]))\nprint(res.numpy().tolist())",
44
"expected_output": "[[1, 4], [2, 5], [3, 6]]"
55
},
66
{
7-
"test": "from tinygrad.tensor import Tensor\nres = transpose_matrix_tg([[1,2],[3,4]])\nprint(res.numpy().tolist())",
7+
"test": "from tinygrad.tensor import Tensor\nres = transpose_matrix_tg(Tensor([[1,2],[3,4]]))\nprint(res.numpy().tolist())",
88
"expected_output": "[[1, 3], [2, 4]]"
99
}
1010
]

0 commit comments

Comments
 (0)