Loading...
Create common special tensors used in deep learning.
PyTorch provides functions to create tensors with specific initial values — tensors of all zeros, all ones, and identity matrices. These are essential for weight initialization, masking, and other operations.
Write a function create_special_tensors(n) that returns a dictionary with three n×n tensors: zeros, ones, and an identity matrix.
Return a dictionary with keys: "zeros", "ones", "identity" — each as a nested list.
(2, 2), "ones"
tensor([[1., 1.],
[1., 1.]])We use torch.ones() with the given shape