Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:56:26+00:00 2026-06-14T06:56:26+00:00

Basically, is it possible to get scipy.ndimage.map_coordinates to return a multi-valued structure, instead of

  • 0

Basically, is it possible to get scipy.ndimage.map_coordinates to return a multi-valued structure, instead of just a scalar? I’d like to be able to interpolate once to retrieve 5 values at a point, rather than having to interpolate 5 times.

Here’s my try at a MWE to demonstrate the problem. I’ll start with a 3D interpolation of a scalar. I won’t go between points for now because that’s not the point.

import numpy as np
from scipy import ndimage
coords = np.array([[1.,1.,1.]])
a = np.arange(3*3*3).reshape(3,3,3)
ndimage.map_coordinates(a,coords.T) # array([13.])

Now, suppose I want a to have pairs of values, not just one. My instinct is

a = np.arange(3*3*3*2).reshape(3,3,3,2)
a[1,1,1] # array([26.,27.])
ndimage.map_coordinates(a[:,:,:],coords.T)  # I'd like array([26.,27.])

Instead of the desired output, I get the following:

RuntimeError                              Traceback (most recent call last)
(...)/<ipython-input-84-77334fb7469f> in <module>()
----> 1 ndimage.map_coordinates(a[:,:,:],np.array([[1.,1.,1.]]).T)

/usr/lib/python2.7/dist-packages/scipy/ndimage/interpolation.pyc in map_coordinates(input, coordinates, output, order, mode, cval, prefilter)
    287         raise RuntimeError('input and output rank must be > 0')
    288     if coordinates.shape[0] != input.ndim:
--> 289         raise RuntimeError('invalid shape for coordinate array')
    290     mode = _extend_mode_to_code(mode)
    291     if prefilter and order > 1:

RuntimeError: invalid shape for coordinate array

I can’t find a permutation of the shapes of any of the structures (a, coords, etc.) that gives me the answer I’m looking for. Also, if there’s a better way to do this than using map_coordinates, go ahead. I thought scipy.interpolate.interp1d might be the way to go but I can’t find any documentation or an inkling of what it might do…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:56:27+00:00Added an answer on June 14, 2026 at 6:56 am

    That’s not possible, I think.

    But tensor product interpolation is not difficult:

    import numpy as np
    from scipy.interpolate import interp1d
    
    def interpn(*args, **kw):
        """Interpolation on N-D. 
    
        ai = interpn(x, y, z, ..., a, xi, yi, zi, ...)
        where the arrays x, y, z, ... define a rectangular grid
        and a.shape == (len(x), len(y), len(z), ...)
        """
        method = kw.pop('method', 'cubic')
        if kw:
            raise ValueError("Unknown arguments: " % kw.keys())
        nd = (len(args)-1)//2
        if len(args) != 2*nd+1:
            raise ValueError("Wrong number of arguments")
        q = args[:nd]
        qi = args[nd+1:]
        a = args[nd]
        for j in range(nd):
            a = interp1d(q[j], a, axis=j, kind=method)(qi[j])
        return a
    
    import matplotlib.pyplot as plt
    
    x = np.linspace(0, 1, 6)
    y = np.linspace(0, 1, 7)
    k = np.array([0, 1])
    z = np.cos(2*x[:,None,None] + k[None,None,:]) * np.sin(3*y[None,:,None])
    
    xi = np.linspace(0, 1, 60)
    yi = np.linspace(0, 1, 70)
    zi = interpn(x, y, z, xi, yi, method='linear')
    
    plt.subplot(221)
    plt.imshow(z[:,:,0].T, interpolation='nearest')
    
    plt.subplot(222)
    plt.imshow(zi[:,:,0].T, interpolation='nearest')
    
    plt.subplot(223)
    plt.imshow(z[:,:,1].T, interpolation='nearest')
    
    plt.subplot(224)
    plt.imshow(zi[:,:,1].T, interpolation='nearest')
    
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I just want to know if its possible to use Nhibernate to migrate
Basically my question is: mysite.php?searchword=vinegar?page=2 In the above url is it possible to GET
Just want to get some views/possible leads on an issue I have. I have
I'm interested if it is possible to send HTTP GET headers with Java. Basically
Basically I am wondering if it is possible to run a console script (.sh)
Possible Duplicate: XNA Mouse Movement Basically, I am creating a game using XNA, and
Basically, I'm wondering if it's possible to take this IF @Value = 1 SELECT
Possible Duplicate: Xcode: Storyboard Tabbed Application Passing Data Back and Forth Basically I have
Is this even possible? Basically, I want to turn these two calls to sub
Basically, this question with a difference... Is it possible to capture print output from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.