liveBook · Manning

Rank

As explained in Deep Learning with R, Third Edition

Tensor rank is the number of axes or dimensions of a tensor.

Rank is the number of axes in a tensor. A scalar has rank 0, a vector has rank 1, and a matrix has rank 2. section 2.2.1 section 2.2.5

A scalar in NumPy

Create x as 12 and inspect x$ndim: the result is 0, confirming that a scalar has no axes. section 2.2.1

Do not confuse a vector’s length with tensor rank. A five-entry vector has one axis and rank 1; a rank-5 tensor has five axes, with potentially different sizes. section 2.2.2

Inspect rank alongside the tensor’s shape and data type:

  • Use length(dim(x)) for R arrays, or x$ndim and op_ndim(x) for backend tensors. section 2.2.5
  • A rank-3 MNIST tensor has shape (60000, 28, 28): 60,000 grayscale images, each represented by a 28 × 28 matrix. section 2.2.5
x <- np_array(x)
x

array([12.,  3.,  6., 14.,  7.])

x$shape

(5,)

x$ndim

1

Inspect a five-entry vector’s shape and ndim to see that its length is 5 while its rank is 1. section 2.2.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains rank through scalars, vectors, and MNIST arrays, then connects it to shape and dtype.
Examples
Uses NumPy scalars, five-entry vectors, and a rank-3 MNIST image tensor.
What you can do after
Evaluate tensor structure by identifying axes and inspecting rank with R or NumPy-style accessors.
How it connects
Links rank with tensors, axes, shape, dimensionality, dtype, and tensor operations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.