Hướng dẫn python fastest 2d interpolation

Given a large (~10 million) number of irregularly spaced points in two dimensions, where each point has some intensity ("weight") associated with it, what existing python implementations are there for interpolating the value at:

  • a specific point at some random position (i.e. point = (0.5, 0.8))
  • a large number of points at random positions (i.e. points = np.random.random((1_000_000, 2)))
  • a regular grid at integer positions (i.e. np.indices((1000, 1000)).T)

I am aware that Delaunay triangulation is often used for this purpose. Are there alternatives to doing it this way?

Do any solutions take advantage of multiple CPU cores or GPUs?

As an example, here is an approach using scipy's LinearNDInterpolator. It does not appear to use more than one CPU core. There are also other options in scipy, but with this question I am especially interested in hearing about other solutions than the ones in scipy.

# The %time tags are IPython magic functions that time that specific line
dimension_shape = (1000, 1000) # we spread the random [0-1] over [0-1000] to avoid floating point errors
N_points = dimension_shape[0] * dimension_shape[1]

known_points = np.random.random((N_points, 2)) * dimension_shape 
known_weights = np.random.random((N_points,))

unknown_point = (0.5, 0.8)
unknown_points = np.random.random((N_points, 2)) * dimension_shape
unknown_grid = np.indices(dimension_shape, dtype=float).T.reshape((-1, 2)) # reshape to a list of 2D points

%time tesselation = Delaunay(known_points) # create grid to know neighbours # 6 sec
%time interp_func = LinearNDInterpolator(tesselation, known_weights) # 1 ms
%time interp_func(unknown_point) # 2 sec # run it once because the scipy function needs to compile 

%time interp_func(unknown_point) # ~ns
%time interp_func(unknown_grid) # 400 ms
%time interp_func(unknown_points) # 1 min 13 sec

# Below I sort the above `unknown_points` array, and try again
%time ind = np.lexsort(np.transpose(unknown_points)[::-1]) # 306 ms
unknown_points_sorted = unknown_points[ind].copy()

%time interp_func(unknown_points_sorted) # 19 sec <- much less than 1 min!

In the above code, things that take an appreciable amount of time are the construction of the Delaunay grid, and interpolation on a non-regular grid of points. Note that sorting the non-regular points first results in a significant speed improvement!

Do not feel the need to give a complete answer from the start. Tackling any aspect of the above is welcome.

Hướng dẫn python input box

Nội dung chínhHàm nhập dữ liệu trong Python2 và Python3Hàm raw_input() trong Python2 và hàm input() trong Python3Hàm input() trong Python2Sự khác biệt giữa input và raw_input ...

Biến và khai báo biến trong python

Ở bài trước mình đã giới thiệu qua với mọi người về ngôn ngữ python rồi, và ở đây mình nhắc lại một lần nữa là series này mình sẽ nói về python ...

Hướng dẫn dùng dictioary python

Kiểu dữ liệu Dictionary trong Python là một tập hợp các cặp key-value không có thứ tự, có thể thay đổi và lập chỉ mục (truy cập phần tử theo chỉ mục). ...

Hướng dẫn dùng panda code python

Trụ sở chính:Văn phòng: Số 27-3RD, Sunrise D, The Manor Central Park, đường Nguyễn Xiển, phường Đại Kim, quận Hoàng Mai, TP. Hà Nội.Liên hệ truyền thông: ...

Hướng dẫn effect size t-test python

There are different types of statistical tests used with data, each used to find out a different insight. When we have data into groups and we need to find out a few properties about them, the ...

Find word in text file python

View DiscussionImprove ArticleSave ArticleReadDiscussView DiscussionImprove ArticleSave ArticleIn this article, we are going to see how to search for a string in text files using PythonExample:string ...

Hướng dẫn python string contains word

Im working with Python, and Im trying to find out if you can tell if a word is in a string.Nội dung chínhHow do I check if a string contains text?How do I check if a string contains a value in ...

Is matlab harder than python

Matlab and Python both can do quite different and incredible things, which makes the question of “Matlab versus Python” interesting. When considering Matlab or Python, the best question to ask is ...

Hướng dẫn identifiers in python javatpoint

Variable is a name that is used to refer to memory location. Python variable is also known as an identifier and used to hold value.In Python, we dont need to specify the type of variable because ...

Hướng dẫn reset loop in python

Just wanted to post an alternative which might be more genearally usable. Most of the existing solutions use a loop index to avoid this. But you dont have to use an index - the key here is that ...

Shift numbers 2 in python assignment expert

Shift Numbers - 2 Given a string, write a program to move all the numbers in it to its start. Input The input will contain a string A. Output The output should contain a string after moving all the ...

Hướng dẫn python apostrophe vs quote

According to the documentation, theyre pretty much interchangeable. Is there a stylistic reason to use one over the other? asked Sep 11, 2008 at 8:18 readonlyreadonly331k107 gold badges203 silver ...

Python combine two lists into 2d list

I would like to merge two lists into one 2d list.list1=[Peter, Mark, John] list2=[1,2,3] intolist3=[[Peter,1],[Mark,2],[John,3]] Alexander9,2473 gold badges51 silver badges58 bronze ...

How do you create a set in python?

The set() function creates a set in Python.Examplelist_numbers = [1, 2, 3, 4, 2, 5] # create set from list numbers_set = set(list_numbers) print(numbers_set) # Output: {1, 2, 3, 4, 5}set() ...

How do i print a row from a database in python?

View DiscussionImprove ArticleSave ArticleReadDiscussView DiscussionImprove ArticleSave ArticleMySQL server is an open-source relational database management system which is a major support for ...

Hướng dẫn python buffer

Xin chào mọi người, hiện mình đang tìm hiểu về python, thấy một phần khá hay và quan trọng đó là xử lý với file. Hôm nay, mình xin viết một bài nhỏ để ...

Hướng dẫn check subclass python

Cho đến nay, những chủ đề về lập trình hướng đối tượng trong Python mà chúng ta đã thảo luận là:Nội dung chính2. Làm thế nào để kiểm tra xem một lớp ...

Hướng dẫn python math exercises

Last update on August 22 2022 13:04:31 (UTC/GMT +8 hours)Python Math [94 exercises with solution] [An editor is available at the bottom of the page to write and execute the scripts.] 1. Write a ...

Hướng dẫn t-score in python

Create code block in pythonBlockIn Python, code block refers to a collection of code that is in the same block or indent. This is most commonly found in classes, functions, and loops.You can where ...

Hướng dẫn options profit calculator python

Welcome to The Command Line Options Profit CalculatorQuick Profit Calculator for Calls and PutsThis is a profit calculator that I created to help me predict my exit with Call option Positions. This ...

Hướng dẫn lr in python

Python là một ngôn ngữ đề cao khả năng dễ đọc, ngắn gọn là quan trọng là LÀM ĐƯỢC NHIỀU THỨ. Ngôn ngữ Python được coi là ngôn ngữ lập trình dễ học ...

Hướng dẫn two-sample t-test python code

In this article, we are going to see how to conduct a two-sample T-test in Python.Nội dung chínhAssumptionsTwo sample T-Test in PythonMethod 1: Using Scipy libraryMethod 2: Two-Sample T-Test with ...

Get last element in dict python

I am having difficulty figuring out what the syntax would be for the last key in a Python dictionary. I know that for a Python list, one may say this to denote the last:list[-1] I also know that one ...

Hướng dẫn python change name file

You may use the following template to rename a file using Python:import os os.rename(rfile pathOLD file name.file type,rfile pathNEW file name.file type) Let’s now review an example with the ...

Hướng dẫn 2d array python numpy

Python Numpy là gì?NumPy là một gói Python là viết tắt của Numerical Python. Đây là thư viện cốt lõi cho scientific computing, nó chứa một đối tượng mảng n chiều ...

Python masked array to numpy array

Rationale#Masked arrays are arrays that may have missing or invalid entries. The numpy.ma module provides a nearly work-alike replacement for numpy that supports data arrays with masks.What is a ...

Hướng dẫn tetris python

09/02/2021 Trò chơi xếp hình là một trò chơi rất quen thuộc với mọi người, đặc biệt là tuổi thơ. Có nhiều cách để viết trò chơi này, video này chỉ là ...

How do you get the day in python?

In this article, you will learn to get todays date and current date and time in Python. We will also format the date and time in different formats using strftime() method.Video: Dates and Times in ...

Hướng dẫn match similar words python

How do I get the probability of a string being similar to another string in Python?I want to get a decimal value like 0.9 (meaning 90%) etc. Preferably with standard Python and ...

Define square function in python

Welcome to the Treehouse CommunityThe Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code ...

Hướng dẫn python-docx header

Microsoft Word (MS)- một trong các tiện ích từ bộ Microsoft Office là một trong những phần mềm phổ biến trong việc tạo ra file document, hỗ trợ đọc và ghi nội ...

Hướng dẫn click python tutorial

Nếu bạn đang muốn tra cứu cách làm có liên quan chủ đề tự học lập trình phần mềm, Nhưng Bạn chưa tra cứu được nguồn nội dung đúng nhất hoặc những ...

Hướng dẫn reverse array python

IntroductionIn this tutorial, we’ll go over the different methods to reverse an array in Python. The Python language does not come with array data structure support. Instead, it has in-built list ...

How to add forward slash in python

How can I add a trailing slash (/ for *nix, for win32) to a directory string, if the tailing slash is not already there? Thanks! Tim Pietzcker318k56 gold badges494 silver badges550 bronze badges ...