Expand or squeeze a tensor #13
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The expand and squeeze operations in tensor manipulation are quite straightforward yet powerful, and they are commonly used in deep learning and data processing.
Expand:
(A, B)
and you want to perform an element-wise operation with a tensor of shape(A, 1)
, you can expand the second tensor to the shape(A, B)
without actually copying data but by creating a view with a new shape.Squeeze:
(A, 1, B, 1)
, applying squeeze can change its shape to(A, B)
. This operation is helpful in removing redundant dimensions that may have resulted from previous operations like convolution or matrix multiplication.These operations are especially useful in programming frameworks for numerical computing and machine learning, such as NumPy, TensorFlow, and PyTorch, allowing for efficient manipulation of tensor shapes without altering the actual data.
Here's a checklist for these operations:
Expand Operation:
Squeeze Operation: