擅长:python、mysql、java
<pre><code>from scipy import array, ndimage
# A B C Y
m = array([ [.20, .54, .26], # 0
[.22, .54, .24], # 1
[.19, .56, .25], # 2
[.19, .58, .23], # 3
[.17, .62, .21] ]) # 4
inputs = array([-1, 0, 0.2, 1, 1.5, 2, 2.5, 3, 4, 8.7])
inputs[inputs < 0] = 0
inputs[inputs > 4] = 4
for y in inputs:
x = ndimage.map_coordinates(m, [y * numpy.ones(3), numpy.arange(3)], order=1)
print y, x
</code></pre>
<hr/>
<pre><code>>>>
0.0 [ 0.2 0.54 0.26]
0.0 [ 0.2 0.54 0.26]
0.2 [ 0.204 0.54 0.256]
1.0 [ 0.22 0.54 0.24]
1.5 [ 0.205 0.55 0.245]
2.0 [ 0.19 0.56 0.25]
2.5 [ 0.19 0.57 0.24]
3.0 [ 0.19 0.58 0.23]
4.0 [ 0.17 0.62 0.21]
4.0 [ 0.17 0.62 0.21]
</code></pre>