Skip to main content

Interpolation Tool for 1d 2d and 3d functions

Project description

Python module for interpolating functions from one, two or three variables.

Examples of using the module:

Examle 1 for 1D interpolation python:

import numpy as np

function_dots = np.array([0, 1, 2, 3, 4, 5])

interpolator = interp_tools.Interp(
    function_dots, 1, np.array([1])
)

for i in range(8):
    print(f"x = {i / 5}, interp val = {interpolator.get_value(i / 5)}, real func val = {i / 5}")
# x = 0.0, interp val = 0.0, real func val = 0.0
# x = 0.2, interp val = 0.19999999999999998, real func val = 0.2
# x = 0.4, interp val = 0.39999999999999997, real func val = 0.4
# x = 0.6, interp val = 0.5999999999999999, real func val = 0.6
# x = 0.8, interp val = 0.7999999999999999, real func val = 0.8
# x = 1.0, interp val = 1.0, real func val = 1.0
# x = 1.2, interp val = 1.2, real func val = 1.2
# x = 1.4, interp val = 1.4, real func val = 1.4

Examle 2 for 1D interpolation python:

import interp_tools
import numpy as np

function_dots = np.zeros(100)
for x in range(100):
    function_dots[x] = (x / 10) ** 2

interpolator = interp_tools.Interp(
    function_dots, 1, np.array([0.1])
)

for i in range(5):
    print(f"x = {i / 5}, interp val = {interpolator.get_value(i / 5)}, real func val = {((i / 5) ** 2) }")
# x = 0.0, interp val = 0.0, real func val = 0.0
# x = 0.2, interp val = 0.04000000000000001, real func val = 0.04000000000000001
# x = 0.4, interp val = 0.16000000000000003, real func val = 0.16000000000000003
# x = 0.6, interp val = 0.35999999999999993, real func val = 0.36
# x = 0.8, interp val = 0.6400000000000001, real func val = 0.6400000000000001

Example for 2D interpolation python:

import interp_tools
import numpy as np

function_dots = np.zeros([100, 100])
for x in range(100):
    for y in range(100):
        function_dots[x, y] = x * y / 100

interpolator = interp_tools.Interp(
    function_dots, 2, np.array([0.1, 0.1])
)

for x in range(1, 4):
    for y in range(1, 4):
        print(f"x = {x / 5}, y = {y / 5}, interp val = {interpolator.get_value(x / 5, y / 5)}, real func val = {((x / 5) * (y / 5)) }")
#x = 0.2, y = 0.2, interp val = 0.04, real func val = 0.04000000000000001
# x = 0.2, y = 0.4, interp val = 0.08, real func val = 0.08000000000000002
# x = 0.2, y = 0.6, interp val = 0.11999999999999998, real func val = 0.12
# x = 0.4, y = 0.2, interp val = 0.08, real func val = 0.08000000000000002
# x = 0.4, y = 0.4, interp val = 0.16, real func val = 0.16000000000000003
# x = 0.4, y = 0.6, interp val = 0.23999999999999996, real func val = 0.24
# x = 0.6, y = 0.2, interp val = 0.11999999999999998, real func val = 0.12
# x = 0.6, y = 0.4, interp val = 0.23999999999999996, real func val = 0.24
# x = 0.6, y = 0.6, interp val = 0.34999999999999987, real func val = 0.36

Example of 3D interpolation python: import interp_tools import numpy as np

function_dots = np.zeros([100, 100, 100])
for x in range(100):
    for y in range(100):
        for z in range(100):
            function_dots[x, y, z] = (x * y / 100 + z / 10)

interpolator = interp_tools.Interp(
    function_dots, 3, np.array([0.1, 0.1, 0.1])
)

for x in range(1, 4):
    for y in range(1, 4):
        for z in range(1, 4):
            print(f"x = {x / 5}, y = {y / 5}, z = {z / 5}, interp val = {interpolator.get_value(x / 5, y / 5, z / 5)}, real func val = {((x / 5) * (y / 5) + z / 5) }")
#x = 0.2, y = 0.2, z = 0.2, interp val = 0.24000000000000002, real func val = 0.24000000000000002
# x = 0.2, y = 0.2, z = 0.4, interp val = 0.44, real func val = 0.44000000000000006
# x = 0.2, y = 0.2, z = 0.6, interp val = 0.6399999999999999, real func val = 0.64
# x = 0.2, y = 0.4, z = 0.2, interp val = 0.28, real func val = 0.28
# x = 0.2, y = 0.4, z = 0.4, interp val = 0.48000000000000004, real func val = 0.48000000000000004
# x = 0.2, y = 0.4, z = 0.6, interp val = 0.6799999999999998, real func val = 0.6799999999999999
# x = 0.2, y = 0.6, z = 0.2, interp val = 0.32, real func val = 0.32
# x = 0.2, y = 0.6, z = 0.4, interp val = 0.52, real func val = 0.52
# x = 0.2, y = 0.6, z = 0.6, interp val = 0.7199999999999999, real func val = 0.72
# x = 0.4, y = 0.2, z = 0.2, interp val = 0.28, real func val = 0.28
# x = 0.4, y = 0.2, z = 0.4, interp val = 0.48000000000000004, real func val = 0.48000000000000004
# x = 0.4, y = 0.2, z = 0.6, interp val = 0.6799999999999998, real func val = 0.6799999999999999
# x = 0.4, y = 0.4, z = 0.2, interp val = 0.36, real func val = 0.36000000000000004
# x = 0.4, y = 0.4, z = 0.4, interp val = 0.56, real func val = 0.56
# x = 0.4, y = 0.4, z = 0.6, interp val = 0.7599999999999999, real func val = 0.76
# x = 0.4, y = 0.6, z = 0.2, interp val = 0.43999999999999995, real func val = 0.44
# x = 0.4, y = 0.6, z = 0.4, interp val = 0.64, real func val = 0.64
# x = 0.4, y = 0.6, z = 0.6, interp val = 0.84, real func val = 0.84
# x = 0.6, y = 0.2, z = 0.2, interp val = 0.32, real func val = 0.32
# x = 0.6, y = 0.2, z = 0.4, interp val = 0.52, real func val = 0.52
# x = 0.6, y = 0.2, z = 0.6, interp val = 0.7199999999999999, real func val = 0.72
# x = 0.6, y = 0.4, z = 0.2, interp val = 0.43999999999999995, real func val = 0.44
# x = 0.6, y = 0.4, z = 0.4, interp val = 0.64, real func val = 0.64
# x = 0.6, y = 0.4, z = 0.6, interp val = 0.84, real func val = 0.84
# x = 0.6, y = 0.6, z = 0.2, interp val = 0.5499999999999999, real func val = 0.56
# x = 0.6, y = 0.6, z = 0.4, interp val = 0.7499999999999998, real func val = 0.76
# x = 0.6, y = 0.6, z = 0.6, interp val = 0.95, real func val = 0.96

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

interp_tools-2.0.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

interp_tools-2.0.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file interp_tools-2.0.0.tar.gz.

File metadata

  • Download URL: interp_tools-2.0.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for interp_tools-2.0.0.tar.gz
Algorithm Hash digest
SHA256 249664475716657df54ce27116054c059f546f5ea42e3e7598f991cfe1f37687
MD5 fef28a32d36ed8378c380848dadaa574
BLAKE2b-256 9e20ff99c0fbf245d6a7ead11179e877d941c52ac18db3ccc2c0208b4b55015c

See more details on using hashes here.

File details

Details for the file interp_tools-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: interp_tools-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for interp_tools-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1628c5d9d85e1fcf5d7759b11cfd3cb61a167df6dd59771f80eb66ab0a251ec
MD5 f6bf60c61782b51647080f9a92ec6b46
BLAKE2b-256 b4764b290b283710bf30b8d124e178361ba5ae36605d966c4a721c1225289296

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page