本文整理匯總了Python中vcmq.N.ones方法的典型用法代碼示例。如果您正苦於以下問題:Python N.ones方法的具體用法?Python N.ones怎麽用?Python N.ones使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vcmq.N
的用法示例。
在下文中一共展示了N.ones方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1:
# 需要導入模塊: from vcmq import N [as 別名]
# 或者: from vcmq.N import ones [as 別名]
"""Test the fortran function :f:func:`cellerr1d`, :f:func:`cellerr1dx` et :f:func:`cellerr1dxx`"""
from vcmq import cdms2, data_sample, N, P, meshcells, minmax, code_file_name, os
from vacumm.misc.grid._interp_ import cellerr1d, cellerr1dx, cellerr1dxx
# Academic example pure 1d
# - data
yi = N.array([-2., 2., 6. , 12., 15.])
vari = N.ma.array(yi)
vari[-1] = N.ma.masked
errm = N.ma.array([1, 2, 1., 2., 3.])
yo = N.array([5., 15])
mv = 1e20
vari = vari.reshape(1, -1).filled(mv)
errm = errm.reshape(1, -1).filled(mv)
errl = N.ones(1)
# - interp
varo, erro = cellerr1d(vari, yi, yo, mv, errm, errl)
# - truth
errot = N.array([
1/N.sqrt(
1/(errm[0, 1]**2+N.abs(yo[0]-yi[1])*errl[0]) +
1/(errm[0, 2]**2+N.abs(yo[0]-yi[2])*errl[0])),
N.sqrt(errm[0, 3]**2+N.abs(yo[1]-yi[3])*errl[0])
])
varot = N.array([
vari[0, 1]/(errm[0, 1]**2+N.abs(yo[0]-yi[1])*errl[0]) +
vari[0, 2]/(errm[0, 2]**2+N.abs(yo[0]-yi[2])*errl[0]),
vari[0, 3]/(errm[0, 3]**2+N.abs(yo[1]-yi[3])*errl[0])
])*errot**2
# - check
result = [(N.testing.assert_allclose, [erro.ravel(), errot]),
示例2:
# 需要導入模塊: from vcmq import N [as 別名]
# 或者: from vcmq.N import ones [as 別名]
"""Test function :func:`~vacumm.misc.filters.generic2d`"""
from vcmq import generic2d, N
# Constant no mask
var0 = N.ones((10, 10))
wei0 = N.ones((3, 3))
N.testing.assert_allclose(generic2d(var0, wei0), 1.)
# Constant with mask
var1 = N.ma.array(var0)
var1[0:3, 0:3] = N.ma.masked
wei1 = wei0
#N.testing.assert_allclose(generic2d(var1, wei1).compressed(), 1.)
# Constant with variable weight
var2 = var1
wei2 = wei1.copy()
wei2[1, 1] = 2.
wei2[[0, 2, 2, 0], [0, 0, 2, 2]] = 0.
N.testing.assert_allclose(generic2d(var2, wei2, mask='minimal').compressed(), 1.)