1 | initial version |
Many of Sage's functions are indeed not designed to work with NumPy arrays.
The error message can vary across versions of Sage.
One option is to use SciPy's Bessel functions instead of Sage's.
Example.
Sage and Python versions used in this example:
sage: print("{}, Python {}.{}.{}".format(version(), *sys.version_info[:3]))
SageMath version 9.8, Release Date: 2023-02-11, Python 3.10.8
Define a NumPy array:
sage: import numpy as np
sage: m = np.array([[1, 1], [1, 1]])
Error when using Sage's bessel_K
with that NumPy array:
sage: bessel_K(1, m)
Traceback (most recent call last)
...
NotImplementedError: The Function bessel_K does not support numpy arrays as arguments
Success with SciPy's kn
:
sage: import scipy
sage: scipy.special.kn(1, m)
array([[0.60190723, 0.60190723],
[0.60190723, 0.60190723]])
2 | No.2 Revision |
Many of Sage's functions are indeed not designed to work with NumPy arrays.
The error message can vary across versions of Sage.
One option is to use SciPy's Bessel functions instead of Sage's.
Example.
Sage and Python versions used in this example:
sage: print("{}, Python {}.{}.{}".format(version(), *sys.version_info[:3]))
SageMath version 9.8, Release Date: 2023-02-11, Python 3.10.8
Define a NumPy array:
sage: import numpy as np
sage: m = np.array([[1, 1], [1, 1]])
Error when using Sage's bessel_K
with that NumPy array:
sage: bessel_K(1, m)
Traceback (most recent call last)
...
NotImplementedError: The Function bessel_K does not support numpy arrays as arguments
Success with SciPy's kn
: using an integer first argument:
sage: import scipy
sage: scipy.special.kn(1, m)
array([[0.60190723, 0.60190723],
[0.60190723, 0.60190723]])
SciPy's kv
allows the first argument to be real and the second one to be complex:
sage: scipy.special.kv(m, 1j*m)
array([[-0.69122984-1.22712623j, -0.69122984-1.22712623j],
[-0.69122984-1.22712623j, -0.69122984-1.22712623j]])