March 2003
Intermediate to advanced
656 pages
39h 30m
English
tolist
a.tolist( )Returns a list L equivalent to
a. For example, if
a
.shape is
(2,3) and
a’s type code is
'd', L is a list of two
lists of three float values each. In other words,
for each valid i and
j,
L
[
i
][
j
]==
a
[
i,j
].
Note that
list(
a
)
converts only the top-level (axis 0) of array
a into a list, and thus is not equivalent
to a
.tolist( ) if
a’s rank is
2 or more. For example:
a=array([[1,2,3],[4,5,6]],typecode='d')
print a.shape # prints: (2,3)
print a # prints: [[1. 2. 3.]
# [4. 5. 6.]]
print list(a)
# prints: [array([1.,2.,3.]), array([4.,5.,6.])]
print a.tolist( )
# prints: [[1.0,2.0,3.0],[4.0,5.0,6.0]]Read now
Unlock full access