A tensor shape is a tuple of dimension sizes describing a multidimensional tensor. A shape of (2, 3) means two rows and three columns; a one-dimensional shape such as (46) contains 46 values. Checking shapes matters because incompatible shapes cause errors during tensor operations. section 2.1.1 section 2.1.3
Use shape information to read, combine, and reorganize tensors:
- Read a tensor's dimensions with its shape attribute; heights_tensor is one-dimensional with 46 values. section 2.1.3
- Concatenate tensors along a selected dimension with cat(); dim=0 joins the first dimension, producing 92 values from two 46-value tensors. section 2.1.3
- Reshape the result to (2, 46), then use one index per dimension to retrieve or slice values. section 2.1.3
From measurements to a two-dimensional tensor
Convert heights from centimeters to feet, concatenate the original and converted tensors, and reshape the 92 values into two rows of 46. The expression heights_reshaped[1,-2] selects the second-to-last value in the second row, returning 6.2664 feet. section 2.1.3
print(heights_tensor.shape)
Inspect a tensor's shape directly with print(heights_tensor.shape), then compare the reported dimensions with the number of indexes needed to access its values. section 2.1.3




