和とスカラー積のある関数空間を扱うモジュール

テーマ、知りたいこと

numpy.ndarray(実数に限る)である入力値に対して複素数を返す関数を複数(要は、関数基底のようなもの)作成しました
(物性についてのDB内にある文献値を線形補完する関数です、これを物質ごとに作成)。
この関数に対して、和、スカラーとの積を計算可能としたいと考えています。
すでにこれを可能としているモジュールがあるのならば、それをそのまま使用するのが良いと思いますが、そのようなモジュールは存在しますでしょうか。

背景、状況

下のように文献値のDBに対して補間を行うクラスを作成しました。
これを物質ごとに多量に作成しています。
使用時にこのクラスのインスタンスの和やスカラー積をとる場面が多く、
さらにその結果である関数に対しても和やスカラー積をとる場面が多く、数回繰り返した場合に面倒な状態となっていることが多いです。
これの処理を容易にするようなモジュールなどがありましたらご紹介いただけますようよろしくお願いします。

python

1from typing import Callable, Literal, Optional, Union, List 2 3import numpy as np 4import numpy.typing as npt 5 6class ComplexInterpolater:7 def __init__(8 self,9 x: npt.ArrayLike, #実数の1dアレイ10 y: npt.ArrayLike, #複素数の1dアレイ11 interpolater: Callable[..., Callable[[npt.ArrayLike], np.ndarray]], #基本的にscipy.interpolate.interp1d12 *args,13 **kwargs,14 ) -> None:15 self.x = np.asarray(x)16 y = np.asarray(y)17 if not self.x.shape[0] == y.shape[0]:18 raise ValueError 19 20 self.real= np.real(y)21 self.imag= np.imag(y)22 self.real_callable: Callable[[npt.ArrayLike], np.ndarray] = interpolater(x, self.real, *args, **kwargs)23 self.imag_callable: Callable[[npt.ArrayLike], np.ndarray] = interpolater(x, self.imag, *args, **kwargs)24 25 def __call__(self, new_x: npt.ArrayLike) -> np.ndarray:26 return self.real_callable(new_x) + 1.0j * self.imag_callable(new_x)27

コメントを投稿

0 コメント