89680

numpy interpolation to increase array size

Question:

this question is related with my previous question <a href="https://stackoverflow.com/questions/32724546/numpy-interpolation-to-increase-a-vector-size" rel="nofollow">How to use numpy interpolation to increase a vector size</a>, but this time I'm looking for a method to do increase the 2D array size and not a vector.

The idea is that I have couples of coordinates (x;y) and I want to smooth the line with a desired number of (x;y) pairs

for a Vector solution I use the answer of @AGML user with very good results

from scipy.interpolate import UnivariateSpline def enlargeVector(vector, size): old_indices = np.arange(0,len(a)) new_length = 11 new_indices = np.linspace(0,len(a)-1,new_length) spl = UnivariateSpline(old_indices,a,k=3,s=0) return spl(new_indices)

Answer1:

You can use the function <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.interpolation.map_coordinates.html" rel="nofollow">map_coordinates</a> from the scipy.ndimage.interpolation module.

import numpy as np from scipy.ndimage.interpolation import map_coordinates A = np.random.random((10,10)) new_dims = [] for original_length, new_length in zip(A.shape, (100,100)): new_dims.append(np.linspace(0, original_length-1, new_length)) coords = np.meshgrid(*new_dims, indexing='ij') B = map_coordinates(A, coords)

Recommend

  • copying unordered keys from one table to ordered values in another
  • AttributeError: 'module' object has no attribute 'choice'
  • Detect angle and rotate an image in Python [closed]
  • Access column with in another column header
  • How to define a chi2 value function for arbitrary function?
  • output label Y train shape keras tensorflow 1.4
  • How to plot normal distribution with percentage of data as label in each band/bin?
  • scipy.optimize.curve_fit: not a proper array of floats error
  • Generating smoothed randoms that follow a distribution
  • python opencv SIFT doesn't work for 8 bit images (JPEG)
  • Installing SciPy on windows
  • How to animate float:left divs? [closed]
  • Replacing points of color by a uniform colored surface
  • Why calculations of eigenvectors of a 2 by 2 matrix with numpy crashes my Python session?
  • Comparing floating point numbers with numpy and scipy
  • Dendrogram or Other Plot from Distance Matrix
  • Matplotlib rotate image file by X degrees
  • Android: how to determine cold start
  • runtime-check whether an instance (Base*) override a parent function (Base::f())
  • Is there a package like bigmemory in R that can deal with large list objects?
  • joining two bezier curves
  • NUnit 3.0 TestCase const custom object arguments
  • ASP.NET MVC 2 Preview 2 - display directory list rather than home/index
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • Initializer list vs. initialization method
  • Is there a javascript serializer for JSON.Net?
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Using $this when not in object context
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • Excel - Autoshape get it's name from cell (value)
  • Check if a string to interpolate provides expected placeholders
  • Join two tables and save into third-sql
  • Perl system calls when running as another user using sudo
  • Where to put my custom functions in Wordpress?
  • Matplotlib draw Spline from multiple points
  • RestKit - RKRequestDelegate does not exist
  • Traverse Array and Display in markup
  • Buffer size for converting unsigned long to string
  • Binding checkboxes to object values in AngularJs