December 2017
Intermediate to advanced
386 pages
10h 42m
English
The numpy.ma module has a collection of functions geared towards common ways of constructing masked arrays. The following code illustrates how to create an array where all entries between 4 and 6 are masked:
x = np.array([ [i+j for j in range(i, i+5)] for i in range(5)])xm = ma.masked_inside(x, 4, 6)
In this code, we first generate the following array:
[[ 0 1 2 3 4] [ 2 3 4 5 6] [ 4 5 6 7 8] [ 6 7 8 9 10] [ 8 9 10 11 12]]
We then use the ma.masked_inside(x, 4, 6) function call to mask all elements of the array that are in the interval [4,6], resulting in the following masked array:
[[0 1 2 3 --] [2 3 -- -- --] [-- -- -- 7 8] [-- 7 8 9 10] [8 9 10 11 12]]
Read now
Unlock full access