Skip to content

[BUG] solve: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (m,m),(m,n)->(m,n) (size 1 is different from 3) #615

@amandalemette

Description

@amandalemette

I'm trying to reproduce the example from the documentation using Google Colaboratory, but I'm getting the error:

solve: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (m,m),(m,n)->(m,n) (size 1 is different from 3)

Reproducing code example:

!pip install pysindy
import pysindy as ps
import numpy as np
import math
np.math = math

t = np.linspace(0, 1, 100)
x = 3 * np.exp(-2 * t)
y = 0.5 * np.exp(t)
X = np.stack((x, y), axis=-1) # First column is x, second is y

model = ps.SINDy(feature_names=["x", "y"])
model.fit(X, t=t)

Error message:


ValueError Traceback (most recent call last)
in <cell line: 0>()
1 model = ps.SINDy(feature_names=["x", "y"])
----> 2 model.fit(X, t=t)

7 frames
/usr/local/lib/python3.11/dist-packages/pysindy/pysindy.py in fit(self, x, t, x_dot, u, multiple_trajectories, unbias, quiet, ensemble, library_ensemble, replace, n_candidates_to_drop, n_subset, n_models, ensemble_aggregator)
341 )
342 self.n_control_features_ = u[0].shape[u[0].ax_coord]
--> 343 x, x_dot = self._process_multiple_trajectories(x, t, x_dot)
344
345 # Set ensemble variables

/usr/local/lib/python3.11/dist-packages/pysindy/pysindy.py in _process_multiple_trajectories(self, x, t, x_dot)
663 x = [xi[:-1] for xi in x]
664 else:
--> 665 x_dot = [
666 self.feature_library.calc_trajectory(
667 self.differentiation_method, xi, ti

/usr/local/lib/python3.11/dist-packages/pysindy/pysindy.py in (.0)
664 else:
665 x_dot = [
--> 666 self.feature_library.calc_trajectory(
667 self.differentiation_method, xi, ti
668 )

/usr/local/lib/python3.11/dist-packages/pysindy/feature_library/base.py in calc_trajectory(self, diff_method, x, t)
85 def calc_trajectory(self, diff_method, x, t):
86 axes = x.dict
---> 87 x_dot = diff_method(x, t=t)
88 return AxesArray(x_dot, axes)
89

/usr/local/lib/python3.11/dist-packages/pysindy/differentiation/base.py in call(self, x, t)
47
48 def call(self, x, t=1):
---> 49 return self._differentiate(x, t)

/usr/local/lib/python3.11/dist-packages/pysindy/differentiation/finite_difference.py in _differentiate(self, x, t)
249 interior = interior + x[tuple(s)] * coeffs[i]
250 else:
--> 251 coeffs = self._coefficients(t)
252 interior = self._accumulate(coeffs, x)
253 s[self.axis] = slice((self.n_stencil - 1) // 2, -(self.n_stencil - 1) // 2)

/usr/local/lib/python3.11/dist-packages/pysindy/differentiation/finite_difference.py in _coefficients(self, t)
100 b = np.zeros(self.n_stencil)
101 b[self.d] = np.math.factorial(self.d)
--> 102 return np.linalg.solve(matrices, [b])
103
104 def _coefficients_boundary_forward(self, t):

/usr/local/lib/python3.11/dist-packages/numpy/linalg/_linalg.py in solve(a, b)
408 with errstate(call=_raise_linalgerror_singular, invalid='call',
409 over='ignore', divide='ignore', under='ignore'):
--> 410 r = gufunc(a, b, signature=signature)
411
412 return wrap(r.astype(result_t, copy=False))

ValueError: solve: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (m,m),(m,n)->(m,n) (size 1 is different from 3)

PySINDy/Python version information:

1.7.5 3.11.12 (main, Apr 9 2025, 08:55:54) [GCC 11.4.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions