Home

Columnmajor

Column-major order is a method of storing multi-dimensional arrays in linear memory in which the elements of each column are stored contiguously. This layout is widely used in scientific computing and in languages that emphasize mathematical column vectors.

In a two-dimensional array with m rows and n columns, the elements are laid out so that

The column-major layout has trade-offs. It yields good locality when iterating down a column, which aligns with

Common examples and contexts include Fortran’s native arrays, MATLAB variables, and the preference of many numerical

See also: row-major order, Fortran, MATLAB, BLAS/LAPACK.

all
elements
of
the
first
column
come
first,
followed
by
the
second
column,
and
so
on.
For
example,
a
3x3
matrix
A
would
be
stored
as
A11,
A21,
A31,
A12,
A22,
A32,
A13,
A23,
A33.
With
zero-based
indexing,
the
linear
index
of
element
A[i][j]
is
i
+
j*m.
This
convention
is
intrinsic
to
languages
such
as
Fortran,
MATLAB,
and
R,
and
is
supported
by
some
array
libraries
in
other
languages.
many
linear-algebra
routines
and
with
BLAS/LAPACK
implementations.
It
can
be
advantageous
for
operations
that
operate
on
column
vectors.
However,
accessing
across
rows
tends
to
cause
cache
misses,
and
interoperability
with
row-major
languages
(like
C)
often
requires
transposition
or
copying
to
convert
layouts.
libraries
for
column-major
storage.
Some
languages
and
libraries
offer
a
choice
between
column-major
and
row-major
or
provide
ways
to
view
data
in
Fortran-ordered
form.