1
"""Backward compatible with arrayfns from Numeric
4
__all__ = ['array_set', 'construct3', 'digitize', 'error', 'find_mask', 'histogram', 'index_sort',
5
'interp', 'nz', 'reverse', 'span', 'to_corners', 'zmin_zmax']
8
from numpy import asarray
10
class error(Exception):
13
def array_set(vals1, indices, vals2):
14
indices = asarray(indices)
16
raise ValueError, "index array must be 1-d"
17
if not isinstance(vals1, ndarray):
18
raise TypeError, "vals1 must be an ndarray"
19
vals1 = asarray(vals1)
20
vals2 = asarray(vals2)
21
if vals1.ndim != vals2.ndim or vals1.ndim < 1:
22
raise error, "vals1 and vals2 must have same number of dimensions (>=1)"
23
vals1[indices] = vals2
25
from numpy import digitize
26
from numpy import bincount as histogram
29
return asarray(arr).argsort(kind='heap')
31
def interp(y, x, z, typ=None):
32
"""y(z) interpolated by treating y(x) as piecewise function
34
res = numpy.interp(z, x, y)
35
if typ is None or typ == 'd':
38
return res.astype('f')
40
raise error, "incompatible typecode"
43
x = asarray(x,dtype=nx.ubyte)
45
raise TypeError, "intput must have 1 dimension."
46
indxs = nx.flatnonzero(x != 0)
47
return indxs[-1].item()+1
50
x = asarray(x,dtype='d')
52
raise ValueError, "input must be 2-d"
60
def span(lo, hi, num, d2=0):
61
x = linspace(lo, hi, num)
65
ret = empty((d2,num),x.dtype)
69
def zmin_zmax(z, ireg):
70
z = asarray(z, dtype=float)
71
ireg = asarray(ireg, dtype=int)
72
if z.shape != ireg.shape or z.ndim != 2:
73
raise ValueError, "z and ireg must be the same shape and 2-d"
74
ix, iy = nx.nonzero(ireg)
75
# Now, add more indices
81
nix = nx.r_[ix, x1m[i1], x1m[i1], ix[i2] ]
82
niy = nx.r_[iy, iy[i1], y1m[i3], y1m[i2]]
83
# remove any negative indices
85
return zres.min().item(), zres.max().item()
88
def find_mask(fs, node_edges):
89
raise NotImplementedError
91
def to_corners(arr, nv, nvsum):
92
raise NotImplementedError
95
def construct3(mask, itype):
96
raise NotImplementedError