A numpy array z
is constructed from 2 Python lists x
and y
where values of y
can be 0
and values of x
are not continuously incrementing (i.e. values can be skipped).
Since y
values can also be 0
, it will be confusing to assign missing values in z
to be 0
as well.
What is the best practice to avoid this confusion?
import numpy as np
# Construct `z`
x = [1, 2, 3, 5, 8, 13]
y = [12, 34, 56, 0, 78, 0]
z = np.ndarray(max(x)+1).astype(np.uint32) # missing values become 0
for i in range(len(x)):
z[x[i]] = y[i]
print(z) # [ 0 12 34 56 0 0 0 0 78 0 0 0 0 0]
print(z[4]) # missing value but is assigned 0
print(z[13]) # non-missing value but also assigned 0