Skip to content

← Tensor Foundations step 1 of 7

Easy Framework

Create a Tensor from a List

Convert a table of numbers into a float32 tensor without changing its row or column order.

Your task

Implement create_tensor(data). The input is a nonempty Python list of rows, where each row is a nonempty list of numbers. All rows have the same length. Return a two-dimensional float32 tensor with one tensor row per input row. Leave the input list unchanged.

For data=[[1, 2, 3], [4, 5, 6]], return shape (2, 3) and values [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]. The outer list determines the number of rows; each inner list determines the columns.

Keep both dimensions even when one has size 1: [[5, 6]] gives (1, 2), while [[5], [6]] gives (2, 1).

Use torch.tensor(data, dtype=torch.float32) or jnp.array(data, dtype=jnp.float32). Specify the dtype explicitly so integer inputs also produce floating-point output. Values are represented at float32 precision, so fractions such as 0.1 may be rounded.

Return the tensor itself, not the input list or a dictionary of shape and values.