本文整理汇总了Python中numpy.ma.array函数的典型用法代码示例。如果您正苦于以下问题:Python array函数的具体用法?Python array怎么用?Python array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self, value, clip=None):
if clip is None:
clip = self.clip
if cbook.iterable(value):
vtype = 'array'
val = ma.asarray(value).astype(numpy.float)
else:
vtype = 'scalar'
val = ma.array([value]).astype(numpy.float)
if self.staticrange is None:
self.autoscale_None(val)
vmin, vmax = self.vmin, self.vmax
else:
self.vmin, self.vmax = None, None
self.autoscale_None(val)
vmin, vmax = self.vmax - self.staticrange, self.vmax
if vmin > vmax:
raise ValueError("minvalue must be less than or equal to maxvalue")
elif vmin==vmax:
result = 0.0 * val
else:
vmin = float(vmin)
vmax = float(vmax)
rmin = float(self.rmin)
rmax = float(self.rmax)
if clip:
mask = ma.getmask(val)
val = ma.array(np.clip(val.filled(vmax), vmin, vmax),
mask=mask)
result = (val-vmin) * ((rmax-rmin) / (vmax-vmin)) + rmin
if vtype == 'scalar':
result = result[0]
return result
开发者ID:priyom,项目名称:priyomdb,代码行数:35,代码来源:vorbis-to-spectrum.py
示例2: setUp
def setUp(self):
self.r1 = Raster('examples/multifact.tif')
self.r2 = Raster('examples/sites.tif')
self.r3 = Raster('examples/two_band.tif')
# r1
data1 = np.array(
[
[1,1,3],
[3,2,1],
[0,3,1]
])
# r2
data2 = np.array(
[
[1,2,1],
[1,2,1],
[0,1,2]
])
mask = [
[False, False, False],
[False, False, False],
[False, False, False]
]
self.data1 = ma.array(data=data1, mask=mask)
self.data2 = ma.array(data=data2, mask=mask)
开发者ID:asiaairsurvey,项目名称:molusce,代码行数:26,代码来源:test_dataprovider.py
示例3: test_pearsonr
def test_pearsonr(self):
# Tests some computations of Pearson's r
x = ma.arange(10)
with warnings.catch_warnings():
# The tests in this context are edge cases, with perfect
# correlation or anticorrelation, or totally masked data.
# None of these should trigger a RuntimeWarning.
warnings.simplefilter("error", RuntimeWarning)
assert_almost_equal(mstats.pearsonr(x, x)[0], 1.0)
assert_almost_equal(mstats.pearsonr(x, x[::-1])[0], -1.0)
x = ma.array(x, mask=True)
pr = mstats.pearsonr(x, x)
assert_(pr[0] is masked)
assert_(pr[1] is masked)
x1 = ma.array([-1.0, 0.0, 1.0])
y1 = ma.array([0, 0, 3])
r, p = mstats.pearsonr(x1, y1)
assert_almost_equal(r, np.sqrt(3)/2)
assert_almost_equal(p, 1.0/3)
# (x2, y2) have the same unmasked data as (x1, y1).
mask = [False, False, False, True]
x2 = ma.array([-1.0, 0.0, 1.0, 99.0], mask=mask)
y2 = ma.array([0, 0, 3, -1], mask=mask)
r, p = mstats.pearsonr(x2, y2)
assert_almost_equal(r, np.sqrt(3)/2)
assert_almost_equal(p, 1.0/3)
开发者ID:andycasey,项目名称:scipy,代码行数:30,代码来源:test_mstats_basic.py
示例4: test_matching_named_fields
def test_matching_named_fields(self):
# Test combination of arrays w/ matching field names
(_, x, _, z) = self.data
zz = np.array(
[("a", 10.0, 100.0), ("b", 20.0, 200.0), ("c", 30.0, 300.0)],
dtype=[("A", "|S3"), ("B", float), ("C", float)],
)
test = stack_arrays((z, zz))
control = ma.array(
[("A", 1, -1), ("B", 2, -1), ("a", 10.0, 100.0), ("b", 20.0, 200.0), ("c", 30.0, 300.0)],
dtype=[("A", "|S3"), ("B", float), ("C", float)],
mask=[(0, 0, 1), (0, 0, 1), (0, 0, 0), (0, 0, 0), (0, 0, 0)],
)
assert_equal(test, control)
assert_equal(test.mask, control.mask)
test = stack_arrays((z, zz, x))
ndtype = [("A", "|S3"), ("B", float), ("C", float), ("f3", int)]
control = ma.array(
[
("A", 1, -1, -1),
("B", 2, -1, -1),
("a", 10.0, 100.0, -1),
("b", 20.0, 200.0, -1),
("c", 30.0, 300.0, -1),
(-1, -1, -1, 1),
(-1, -1, -1, 2),
],
dtype=ndtype,
mask=[(0, 0, 1, 1), (0, 0, 1, 1), (0, 0, 0, 1), (0, 0, 0, 1), (0, 0, 0, 1), (1, 1, 1, 0), (1, 1, 1, 0)],
)
assert_equal(test, control)
assert_equal(test.mask, control.mask)
开发者ID:haadkhan,项目名称:cerebri,代码行数:33,代码来源:test_recfunctions.py
示例5: test_matching_named_fields
def test_matching_named_fields(self):
# Test combination of arrays w/ matching field names
(_, x, _, z) = self.data
zz = np.array([('a', 10., 100.), ('b', 20., 200.), ('c', 30., 300.)],
dtype=[('A', '|S3'), ('B', float), ('C', float)])
test = stack_arrays((z, zz))
control = ma.array([('A', 1, -1), ('B', 2, -1),
(
'a', 10., 100.), ('b', 20., 200.), ('c', 30., 300.)],
dtype=[('A', '|S3'), ('B', float), ('C', float)],
mask=[(0, 0, 1), (0, 0, 1),
(0, 0, 0), (0, 0, 0), (0, 0, 0)])
assert_equal(test, control)
assert_equal(test.mask, control.mask)
test = stack_arrays((z, zz, x))
ndtype = [('A', '|S3'), ('B', float), ('C', float), ('f3', int)]
control = ma.array([('A', 1, -1, -1), ('B', 2, -1, -1),
('a', 10., 100., -1), ('b', 20., 200., -1),
('c', 30., 300., -1),
(-1, -1, -1, 1), (-1, -1, -1, 2)],
dtype=ndtype,
mask=[(0, 0, 1, 1), (0, 0, 1, 1),
(0, 0, 0, 1), (0, 0, 0, 1), (0, 0, 0, 1),
(1, 1, 1, 0), (1, 1, 1, 0)])
assert_equal(test, control)
assert_equal(test.mask, control.mask)
开发者ID:vbasu,项目名称:numpy,代码行数:27,代码来源:test_recfunctions.py
示例6: test_peak_with_mask
def test_peak_with_mask(self):
# Single value in column masked.
latitude = iris.coords.DimCoord(np.arange(0, 5, 1),
standard_name='latitude',
units='degrees')
cube = iris.cube.Cube(ma.array([1, 4, 2, 3, 2], dtype=np.float32),
standard_name='air_temperature',
units='kelvin')
cube.add_dim_coord(latitude, 0)
cube.data[3] = ma.masked
collapsed_cube = cube.collapsed('latitude', iris.analysis.PEAK)
self.assertArrayAlmostEqual(collapsed_cube.data,
np.array([4.024977], dtype=np.float32))
self.assertTrue(ma.isMaskedArray(collapsed_cube.data))
self.assertEqual(collapsed_cube.data.shape, (1,))
# Whole column masked.
cube.data[:] = ma.masked
collapsed_cube = cube.collapsed('latitude', iris.analysis.PEAK)
masked_array = ma.array(ma.masked)
self.assertTrue(ma.allequal(collapsed_cube.data, masked_array))
self.assertTrue(ma.isMaskedArray(collapsed_cube.data))
self.assertEqual(collapsed_cube.data.shape, (1,))
开发者ID:Jozhogg,项目名称:iris,代码行数:26,代码来源:test_peak.py
示例7: preprocessing
def preprocessing(gridding_method, Time, ColumnAmountNO2Trop,
ColumnAmountNO2TropStd, FoV75Area, CloudRadianceFraction,
RootMeanSquareErrorOfFit, SolarZenithAngle, VcdQualityFlags,
XTrackQualityFlags, **kwargs):
# mask of bad values
mask = ColumnAmountNO2Trop.mask | ColumnAmountNO2TropStd.mask
# mask low quality data
mask |= RootMeanSquareErrorOfFit > 0.0003
mask |= SolarZenithAngle > 85
mask |= VcdQualityFlags % 2 != 0
mask |= XTrackQualityFlags
# set invalid cloud cover to 100% -> smallest weight
CloudRadianceFraction[CloudRadianceFraction.mask] = 1.0
# values and errors
values = ma.array(ColumnAmountNO2Trop, mask=mask)
errors = ma.array(ColumnAmountNO2TropStd, mask=mask)
# weight based on stddev and pixel area (see Wenig et al., 2008)
stddev = 1.5e15 * (1.0 + 3.0 * ma.array(CloudRadianceFraction, mask=mask))
area = FoV75Area.reshape(1, FoV75Area.size)
area = area.repeat(ColumnAmountNO2Trop.shape[0], axis=0)
if gridding_method.startswith('psm'):
weights = ma.array(1.0 / area, mask=mask)
else:
weights = ma.array(1.0 / (area * stddev**2), mask=mask)
return values, errors, stddev, weights
开发者ID:gkuhl,项目名称:omi,代码行数:32,代码来源:OMNO2_Trop.py
示例8: setUp
def setUp(self):
self.factor = Raster('../../examples/multifact.tif')
#~ [1,1,3]
#~ [3,2,1]
#~ [0,3,1]
self.sites = Raster('../../examples/sites.tif')
#~ [1,2,1],
#~ [1,2,1],
#~ [0,1,2]
self.sites.resetMask(maskVals= [0])
self.mask = [
[False, False, False,],
[False, False, False,],
[True, False, False,]
]
fact = [
[1, 1, 3,],
[3, 2, 1,],
[0, 3, 1,]
]
site = [
[False, True, False,],
[False, True, False,],
[False, False, True,]
]
self.factraster = ma.array(data = fact, mask=self.mask, dtype=np.int)
self.sitesraster = ma.array(data = site, mask=self.mask, dtype=np.bool)
开发者ID:nextgis,项目名称:molusce,代码行数:29,代码来源:test_manager.py
示例9: hooray
def hooray(year,tile):
file_pattern = 'files/data/MCD15A2.A%s*.%s.*'%(year,tile)
filenames = np.sort(glob(file_pattern))
selected_layers = [ "Lai_1km", "FparLai_QC", "LaiStdDev_1km" ]
file_template = 'HDF4_EOS:EOS_GRID:"%s":MOD_Grid_MOD15A2:%s'
lai_all = []
lai_sd_all = []
for filename in filenames:
data = {}
for i, layer in enumerate ( selected_layers ):
this_file = file_template % ( filename, layer )
g = gdal.Open ( this_file )
if g is None:
raise IOError
data[layer] = g.ReadAsArray()
lai = data['Lai_1km'] * 0.1
lai_sd = data['LaiStdDev_1km'] * 0.1
mask = data['FparLai_QC'] & 1
laim = ma.array(lai,mask=mask)
laim_sd = ma.array(lai_sd,mask=mask)
lai_all.append(laim)
lai_sd_all.append(laim_sd)
lai_all = ma.array(lai_all)
lai_sd_all = ma.array(lai_sd_all)
return lai_all, lai_sd_all
开发者ID:ThomasG77,项目名称:geogg122,代码行数:35,代码来源:mlai.py
示例10: getShiibaVectorField
def getShiibaVectorField(shiibaCoeffs, phi1, gridSize=25, name="",\
key="Shiiba vector field", title="UpWind Scheme"):
""" plotting vector fields from shiiba coeffs
input: shiiba coeffs (c1,c2,c3,..,c6) for Ui=c1.I + c2.J +c3, Vj=c4.I +c5.J+c6
and transform it via I=y, J=x, to Ux = c5.x+c4.y+c6, Vy = c2.x+c1.y+c3
"""
# 1. setting the variables
# 2. setting the stage
# 3. plotting
# 4. no need to save or print to screen
# 1. setting the variables
c1, c2, c3, c4, c5, c6 = shiibaCoeffs
c5, c4, c6, c2, c1, c3 = c1, c2, c3, c4, c5, c6 # x,y <- j, i switch
# 2. setting the stage
height= phi1.matrix.shape[0]
width = phi1.matrix.shape[1]
mask = phi1.matrix.mask
name = "shiiba vector field for "+ phi1.name
imagePath = phi1.name+"shiibaVectorField.png"
key = key
ploTitle = title
gridSize = gridSize
X, Y = np.meshgrid(range(width), range(height))
Ux = c1*X + c2*Y + c3
Vy = c4*X + c5*Y + c6
Ux = ma.array(Ux, mask=mask)
Vy = ma.array(Vy, mask=mask)
#constructing the vector field object
vect = pattern.VectorField(Ux, Vy, name=name, imagePath=imagePath, key=key,
title=title, gridSize=gridSize)
return vect
开发者ID:rainly,项目名称:armor,代码行数:33,代码来源:regression.py
示例11: spike_flag
def spike_flag(data,masked,freq,percent):
"""
Flags out RFI spikes using a 11 bin filter
Can be used with either time or freq
percent is a percentage level cut (100 would be twice the 11 bin average)
Needs to be applied to masked data.
"""
new_mask = np.zeros(len(data))
new_array = ma.array(data,mask=masked)
new_comp = ma.compressed(new_array)
freq_array = ma.array(freq,mask=masked)
new_freq = ma.compressed(freq_array)
for i in range(0,len(data)):
if masked[i]==1.0:
new_mask[i] = 1.0
for i in range(5,len(new_comp)-5):
group = new_comp[i-5]+new_comp[i-4]+new_comp[i-3]+new_comp[i-2]+new_comp[i-1]+new_comp[i]+new_comp[i+1]+new_comp[i+2]+new_comp[i+3]+new_comp[i+4]+new_comp[i+5]
mean_group = group/11.
if new_comp[i]/mean_group>=(1+percent/100.):
comp_freq = new_freq[i]
for j in range(0,len(freq)):
if freq[j]==comp_freq:
index=j
new_mask[index]= 1.0
elif new_comp[i]/mean_group<=1/(1+percent/100.):
comp_freq = new_freq[i]
for j in range(0,len(freq)):
if freq[j]==comp_freq:
index=j
new_mask[index]= 1.0
return new_mask
开发者ID:tcv,项目名称:hibiscus,代码行数:33,代码来源:file_funcs.py
示例12: plotCurves
def plotCurves(c1, c2):
name1, t, avg1, top1, bottom1 = c1
name2, t, avg2, top2, bottom2 = c2
pl.plot(t, np.zeros(len(t)), 'k-')
s1 = ma.array(avg1)
s2 = ma.array(avg2)
zx1 = np.logical_and(np.greater_equal(top1, 0), np.less_equal(bottom1, 0))
zx2 = np.logical_and(np.greater_equal(top2, 0), np.less_equal(bottom2, 0))
ix = np.logical_or(
np.logical_and(
np.greater_equal(top1, top2),
np.less_equal(bottom1, top2)),
np.logical_and(
np.greater_equal(top1, bottom2),
np.less_equal(bottom1, bottom2)))
mask1 = np.logical_or(zx1, ix)
mask2 = np.logical_or(zx2, ix)
print mask1
print mask2
print zx1
print zx2
print ix
pl.plot(t, s1, "k--", linewidth=1)
pl.plot(t, s2, "k-", linewidth=1)
s1.mask = ix
s2.mask = ix
pl.plot(t, s1, "k--", linewidth=3, label=name1)
pl.plot(t, s2, "k-", linewidth=3, label=name2)
pl.xlabel('Time (secs)')
pl.ylabel("Pearson correlation")
开发者ID:estebanhurtado,项目名称:cutedots,代码行数:32,代码来源:plot2.py
示例13: __call__
def __call__(self, value, clip=None):
if clip is None:
clip = self.clip
if cbook.iterable(value):
vtype = 'array'
val = ma.asarray(value).astype(np.float)
else:
vtype = 'scalar'
val = ma.array([value]).astype(np.float)
self.autoscale_None(val)
vmin, vmax = self.vmin, self.vmax
cmin, cmax = self.cmin * vmin, self.cmax * vmax
if vmin > vmax:
raise ValueError("minvalue must be less than or equal to maxvalue")
elif vmin == vmax:
result = 0.0 * val
else:
if clip:
mask = ma.getmask(val)
val = ma.array(np.clip(val.filled(vmax), vmin, vmax),
mask=mask)
result = 0. * val + 0.5
result[val > cmax] = (ma.log10(val[val > cmax]) - ma.log10(cmax)) / (np.log10(vmax) - np.log10(cmax)) / 2. + 0.5
result[val < cmin] = -(ma.log10(-val[val < cmin]) - ma.log10(-cmin)) / (np.log10(-vmin) - np.log10(-cmin)) / 2. + 0.5
if vtype == 'scalar':
result = result[0]
return result
开发者ID:iceseismic,项目名称:sito,代码行数:27,代码来源:imaging.py
示例14: fitModel
def fitModel(traj, mode=None, maxMissing=0.9, excludeEdge=None):
traj = deepcopy(traj)
if mode == 'onFood':
traj.excluded = normDistToFood(traj)>1.1
if mode == 'offFood':
traj.excluded = normDistToFood(traj)<=1.1
if excludeEdge is not None:
width, height = (traj.h5ref['cropRegion'][-2:]/
traj.pixelsPerMicron)
xsel = np.logical_or(traj.X[:,0] < excludeEdge,
traj.X[:,0] > width - excludeEdge)
ysel = np.logical_or(traj.X[:,1] < excludeEdge,
traj.X[:,1] > height - excludeEdge)
sel = np.logical_or(xsel, ysel)
traj.excluded = np.logical_or(traj.excluded, sel)
m = wtm.Helms2015CentroidModel()
# check whether there is sufficient datapoints to fit model
if fractionMissing(traj) > maxMissing:
p = ma.array(m.toParameterVector()[0], dtype=float)
p[:] = ma.masked
return p.filled(np.NAN).astype(float)
else:
try:
m.fit(traj, windowSize=100., plotFit=False)
return ma.array(m.toParameterVector()[0]).filled(np.NAN).astype(float)
except Exception as e:
print 'Error during ' + repr(traj) + repr(e)
p = ma.array(m.toParameterVector()[0])
p[:] = ma.masked
return p.filled(np.NAN).astype(float)
开发者ID:stephenhelms,项目名称:WormTracker,代码行数:31,代码来源:fit_centroid_model_data.py
示例15: __call__
def __call__(self, value, clip=None, midpoint=None):
if clip is None:
clip = self.clip
if cbook.iterable(value):
vtype = 'array'
val = ma.asarray(value).astype(np.float)
else:
vtype = 'scalar'
val = ma.array([value]).astype(np.float)
self.autoscale_None(val)
vmin, vmax = self.vmin, self.vmax
if vmin > vmax:
raise ValueError("minvalue must be less than or equal to maxvalue")
elif vmin==vmax:
return 0.0 * val
else:
if clip:
mask = ma.getmask(val)
val = ma.array(np.clip(val.filled(vmax), vmin, vmax),
mask=mask)
result = (val-vmin) * (1.0/(vmax-vmin))
#result = (ma.arcsinh(val)-np.arcsinh(vmin))/(np.arcsinh(vmax)-np.arcsinh(vmin))
result = result**(1./self.nthroot)
if vtype == 'scalar':
result = result[0]
return result
开发者ID:Fade89,项目名称:agpy,代码行数:31,代码来源:sqrt_norm.py
示例16: test_woe
def test_woe(self):
wPlus1 = np.math.log ( (2.0/3 + EPSILON)/(2.0/5 + EPSILON) )
wMinus1 = np.math.log ( (1.0/3 + EPSILON)/(3.0/5 + EPSILON) )
wPlus2 = np.math.log ( (1.0/3 + EPSILON)/(EPSILON) )
wMinus2 = np.math.log ( (2.0/3 + EPSILON)/(1.0 + EPSILON) )
wPlus3 = np.math.log ( (EPSILON)/(3.0/5 + EPSILON) )
wMinus3 = np.math.log ( (1.0 + EPSILON)/(2.0/5 + EPSILON) )
# Binary classes
ans = [
[wPlus1, wPlus1, wMinus1,],
[wMinus1, wMinus1, wPlus1, ],
[None, wMinus1, wPlus1, ]
]
ans = ma.array(data=ans, mask=self.mask)
np.testing.assert_equal(woe(self.factor, self.sites), ans)
# Multiclass
w1, w2, w3 = (wPlus1 + wMinus2+wMinus3), (wPlus2 + wMinus1 + wMinus3), (wPlus3 + wMinus1 + wMinus2)
ans = [
[w1, w1, w3,],
[w3, w2, w1,],
[ 0, w3, w1,]
]
ans = ma.array(data=ans, mask=self.mask)
weights = woe(self.multifact, self.sites)
np.testing.assert_equal(ans, weights)
开发者ID:asiaairsurvey,项目名称:molusce,代码行数:30,代码来源:test_model.py
示例17: common_ma_setup
def common_ma_setup():
data2D = ma.array([np.random.rand(25).reshape(5,5),
np.random.rand(25).reshape(5,5),
np.random.rand(25).reshape(5,5),
np.random.rand(25).reshape(5,5),
np.random.rand(25).reshape(5,5),],
mask=[np.random.rand(25).reshape(5,5)>.5,
np.random.rand(25).reshape(5,5)>.5,
np.random.rand(25).reshape(5,5)>.5,
np.random.rand(25).reshape(5,5)>.5,
np.random.rand(25).reshape(5,5)>.5,]
)
data1D = ma.array(np.random.rand(25),
mask=np.random.rand(25)>0.9,
fill_value=-9999)
dtype5R = [('a',float),('b',int),('c','|S3')]
data5N = ma.array(zip(np.random.rand(5),
np.arange(5),
'ABCDE'),
dtype=dtype5R)
data5R = mr.fromarrays([np.random.rand(5),
np.arange(5),
('A','B','C','D','E')],
dtype=dtype5R)
data5R._mask['a'][0]=True
data5R._mask['b'][2]=True
data5R._mask['c'][-1]=True
return dict(data1D=data1D,
data2D=data2D,
data5N=data5N,
data5R=data5R)
开发者ID:ndawe,项目名称:scikit-timeseries,代码行数:31,代码来源:test_tstables.py
示例18: autosearch_peaks
def autosearch_peaks(dataset,limits,params):
"""
Detects peaks in the y axis of a dataset and returns a list of PeakRowUI objects for each peak
"""
xdata=dataset.data[:,0]
#limits=(xdata[0],xdata[-1])
iBeg = np.searchsorted(xdata,limits[0])
iFin = np.searchsorted(xdata,limits[1])
x = xdata[iBeg:iFin]
y0 = dataset.data[iBeg:iFin,1]
y1 = copy.copy(y0)
ysig = np.std(y1)
offset = [-1,1]
ymask = ma.array(y0,mask=(y0<ysig))
for off in offset:
ymask = ma.array(ymask,mask=(ymask-np.roll(y0,off)<=0.))
indx = ymask.nonzero()
mags = ymask[indx]
poss = x[indx]
iPeak=0
max_peaks=50 # arbitrarily set for now
if len(poss)>max_peaks:
return None
else:
for pos,mag in zip(poss,mags):
params.update(setPeakparms(pos,mag,params,iPeak))
iPeak+=1
return createPeakRows(params)
开发者ID:AustralianSynchrotron,项目名称:pdviper,代码行数:28,代码来源:peak_fitting.py
示例19: colicTest
def colicTest():
frTrain = open('horseColicTraining.txt')
frTest = open('horseColicTest.txt')
trainingSet = []
trainingLabels = []
for line in frTrain.readlines():
currLine = line.strip().split('\t')
lineArr = []
for i in range(21):
lineArr.append(float(currLine[i]))
trainingSet.append(lineArr)
trainingLabels.append(float(currLine[21]))
trainWeights = stocGradAscent1(array(trainingSet), trainingLabels, 200)
errorCount = 0
numTestVec = 0.0
for line in frTest.readlines():
numTestVec += 1.0
currLine = line.strip().split('\t')
lineArr = []
for i in range(21):
lineArr.append(float(currLine[i]))
if int(classifyVector(array(lineArr), trainWeights)) != int(currLine[21]):
errorCount += 1
errorRate = (float(errorCount) / numTestVec)
print "the error rate of this test is: %f" % errorRate
return errorRate
开发者ID:daihui,项目名称:machinelearning,代码行数:26,代码来源:logRegres.py
示例20: test_user_missing_values
def test_user_missing_values(self):
data = "A, B, C\n0, 0., 0j\n1, N/A, 1j\n-9, 2.2, N/A\n3, -99, 3j"
basekwargs = dict(dtype=None, delimiter=",", names=True)
mdtype = [("A", int), ("B", float), ("C", complex)]
#
test = np.mafromtxt(StringIO(data), missing_values="N/A", **basekwargs)
control = ma.array(
[(0, 0.0, 0j), (1, -999, 1j), (-9, 2.2, -999j), (3, -99, 3j)],
mask=[(0, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, 0)],
dtype=mdtype,
)
assert_equal(test, control)
#
basekwargs["dtype"] = mdtype
test = np.mafromtxt(StringIO(data), missing_values={0: -9, 1: -99, 2: -999j}, **basekwargs)
control = ma.array(
[(0, 0.0, 0j), (1, -999, 1j), (-9, 2.2, -999j), (3, -99, 3j)],
mask=[(0, 0, 0), (0, 1, 0), (1, 0, 1), (0, 1, 0)],
dtype=mdtype,
)
assert_equal(test, control)
#
test = np.mafromtxt(StringIO(data), missing_values={0: -9, "B": -99, "C": -999j}, **basekwargs)
control = ma.array(
[(0, 0.0, 0j), (1, -999, 1j), (-9, 2.2, -999j), (3, -99, 3j)],
mask=[(0, 0, 0), (0, 1, 0), (1, 0, 1), (0, 1, 0)],
dtype=mdtype,
)
assert_equal(test, control)
开发者ID:hector1618,项目名称:numpy,代码行数:29,代码来源:test_io.py
注:本文中的numpy.ma.array函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论