March 2003
Intermediate to advanced
656 pages
39h 30m
English
zeros
zeros(shapetuple,typecode=Int,savespace=False)
Returns an array a such that
a
.shape==
shapetuple. All of
a’s elements are
0.
Note that, by default, identity,
ones, and zeros all return
arrays whose type is Int. Be sure to specify
explicitly a different type code, such as Float,
if that is what you really want. For example, be sure to avoid the
following common mistake:
a = zeros(3) a[0] = 0.3 # a is array([0,0,0])
Since a is Int in this snippet,
the 0.3 we assign to one of its items gets
truncated to the integer 0. Instead, you typically
want something closer to the following:
a = zeros(3,Float) a[0] = 0.3 # a is array([0.3,0.,0.])
Here, we have explicitly specified Float as the
type code for a, and therefore no truncation
occurs when we assign 0.3 to one of
a’s items.