Tensor Operations
Tensor Operations
Implement fundamental tensor operations that are the building blocks of deep learning.
Functions to implement
1. create_zeros(shape)
Create a tensor filled with zeros.
- Input: Shape tuple (e.g., (3, 4))
- Output: Nested list of zeros
2. reshape(tensor, new_shape)
Reshape a tensor to new dimensions.
- Total elements must remain the same
3. transpose(matrix)
Transpose a 2D matrix (swap rows and columns).
4. matmul(A, B)
Matrix multiplication of two 2D matrices.
5. elementwise_add(A, B)
Add two tensors element-wise.
6. sum_along_axis(tensor, axis)
Sum along a specific axis.
Examples
create_zeros((2, 3)) # [[0,0,0], [0,0,0]]
transpose([[1, 2], [3, 4]]) # [[1, 3], [2, 4]]
matmul([[1, 2]], [[3], [4]]) # [[11]]
Run tests to see results
No issues detected