SciPy

numpy.polynomial.polyutils.mapdomain

numpy.polynomial.polyutils.mapdomain(x, old, new)[source]

Apply linear map to input points.

The linear map offset + scale*x that maps the domain old to the domain new is applied to the points x.

Parameters:

x : array_like

Points to be mapped. If x is a subtype of ndarray the subtype will be preserved.

old, new : array_like

The two domains that determine the map. Each must (successfully) convert to 1-d arrays containing precisely two values.

Returns:

x_out : ndarray

Array of points of the same shape as x, after application of the linear map between the two domains.

See also

getdomain, mapparms

Notes

Effectively, this implements:

x\_out = new[0] + m(x - old[0])

where

m = \frac{new[1]-new[0]}{old[1]-old[0]}

Examples

>>> from numpy.polynomial import polyutils as pu
>>> old_domain = (-1,1)
>>> new_domain = (0,2*np.pi)
>>> x = np.linspace(-1,1,6); x
array([-1. , -0.6, -0.2,  0.2,  0.6,  1. ])
>>> x_out = pu.mapdomain(x, old_domain, new_domain); x_out
array([ 0.        ,  1.25663706,  2.51327412,  3.76991118,  5.02654825,
        6.28318531])
>>> x - pu.mapdomain(x_out, new_domain, old_domain)
array([ 0.,  0.,  0.,  0.,  0.,  0.])

Also works for complex numbers (and thus can be used to map any line in the complex plane to any other line therein).

>>> i = complex(0,1)
>>> old = (-1 - i, 1 + i)
>>> new = (-1 + i, 1 - i)
>>> z = np.linspace(old[0], old[1], 6); z
array([-1.0-1.j , -0.6-0.6j, -0.2-0.2j,  0.2+0.2j,  0.6+0.6j,  1.0+1.j ])
>>> new_z = P.mapdomain(z, old, new); new_z
array([-1.0+1.j , -0.6+0.6j, -0.2+0.2j,  0.2-0.2j,  0.6-0.6j,  1.0-1.j ])