Citat:
Ursprungligen postat av
janblommgren
Sitter och lser om numeriska berkningar med matplotlib ,numpy. Nu skrivs det om sk masked arrays,
men gur gr man egentligen i praktiken fr att f fram koefficienterna i den sk masked array?
Givet r en funktion typ
f(x,y)=cos(y*pi/Rsqrt(3))*cos(pi/2sqrt(3)R(y+3x) osv med flera termer i x och y
Frn denna tas fram en sk masked array,
mask=(y<=np.sqrt(3)/2R)*(y>=-np.sqrt(3)/2*R osv.
Det jag undrar ver r hur dessa koefficienter eller tal tas fram. Nollstllena till f(x,y)?
Sedan i sista steget stts mask in i uttrycket fr z=f(x,y). Dvs x erstts med mask
Jag tycker det fanns ett ganska talande exempel hr i
Numpy-dokumentationen:
Citat:
Data with a given value representing missing data
Lets consider a list of elements, x, where values of -9999. represent missing data. We wish to compute the average value of the data and the vector of anomalies (deviations from the average):
Kod:
import numpy.ma as ma
x = [0.,1.,-9999.,3.,4.]
mx = ma.masked_values (x, -9999.)
print(mx.mean())
2.0
Kod:
print(mx - mx.mean())
[-2.0 -1.0 -- 1.0 2.0]
[-2.0 -1.0 -- 1.0 2.0]
Citat:
Ignoring extreme values
Lets consider an array d of floats between 0 and 1. We wish to compute the average of the values of d
while ignoring any data outside the range [0.2, 0.9]:
Kod:
d = np.linspace(0, 1, 20)
print(d.mean() - ma.masked_outside(d, 0.2, 0.9).mean())
-0.05263157894736836
De "maskerade" delarna av masked array bestms hr med masked_values respektive masked_outside.
Dessa maskerade delar
ignoreras vid numpys rkneoperationer p data-arrayen.
Du kan istllet
fylla i de saknade (maskerade) medlemmarna av "arrayen":
Citat:
Filling in the missing data
Suppose now that we wish to print that same data, but with the missing values replaced by the average value.
Kod:
print(mx.filled(mx.mean()))
[ 0. 1. 2. 3. 4.]