MCPcopy Create free account
hub / github.com/numpy/numpy / mapdomain

Function mapdomain

numpy/polynomial/polyutils.py:307–372  ·  view source on GitHub ↗

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 p

(x, old, new)

Source from the content-addressed store, hash-verified

305 return off, scl
306
307def mapdomain(x, old, new):
308 """
309 Apply linear map to input points.
310
311 The linear map ``offset + scale*x`` that maps the domain `old` to
312 the domain `new` is applied to the points `x`.
313
314 Parameters
315 ----------
316 x : array_like
317 Points to be mapped. If `x` is a subtype of ndarray the subtype
318 will be preserved.
319 old, new : array_like
320 The two domains that determine the map. Each must (successfully)
321 convert to 1-d arrays containing precisely two values.
322
323 Returns
324 -------
325 x_out : ndarray
326 Array of points of the same shape as `x`, after application of the
327 linear map between the two domains.
328
329 See Also
330 --------
331 getdomain, mapparms
332
333 Notes
334 -----
335 Effectively, this implements:
336
337 .. math::
338 x\\_out = new[0] + m(x - old[0])
339
340 where
341
342 .. math::
343 m = \\frac{new[1]-new[0]}{old[1]-old[0]}
344
345 Examples
346 --------
347 >>> from numpy.polynomial import polyutils as pu
348 >>> old_domain = (-1,1)
349 >>> new_domain = (0,2*np.pi)
350 >>> x = np.linspace(-1,1,6); x
351 array([-1. , -0.6, -0.2, 0.2, 0.6, 1. ])
352 >>> x_out = pu.mapdomain(x, old_domain, new_domain); x_out
353 array([ 0. , 1.25663706, 2.51327412, 3.76991118, 5.02654825, # may vary
354 6.28318531])
355 >>> x - pu.mapdomain(x_out, new_domain, old_domain)
356 array([0., 0., 0., 0., 0., 0.])
357
358 Also works for complex numbers (and thus can be used to map any line in
359 the complex plane to any other line therein).
360
361 >>> i = complex(0,1)
362 >>> old = (-1 - i, 1 + i)
363 >>> new = (-1 + i, 1 - i)
364 >>> z = np.linspace(old[0], old[1], 6); z

Callers

nothing calls this directly

Calls 1

mapparmsFunction · 0.85

Tested by

no test coverage detected