Name
flat
Synopsis
a
.flat
is an
attribute that contains an array with rank 1 and of the same size as
a
, sharing
a
’s data. Indexing or
slicing a
.flat
lets you
access or change a
’s
elements through this alternate view of a
.
Trying to access a
.flat
raises a TypeError
exception if
a
is noncontiguous. When
a
is contiguous,
a
.flat
is in row-major
order. This means that, for example, when
a
’s shape is
(7,4)
(i.e., a
is a
two-dimensional matrix with seven rows and four columns),
a
.flat[
i
]
is the same as
a
[divmod(
i
,4)]
for all i
in range(28)
.
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.