Часть кода, которая вызывает у меня проблему:
Код: Выделить всё
import scipy.linalg as la
[...]
corr_j = simple_corr(data_jack, mask)
#compute the eigenvalues
eig_j = np.zeros((nOps, L0, L0))
for t0 in range(2,L0//2-1):
for t1 in range(t0+1, L0//2):
#solve the generalized eigenvalue problem C(t) v = lambda(t) C(t0) v
C = corr_j[:,:,t1]
C0 = corr_j[:,:,t0]
print(f"C = {C.shape}")
print(f"C = {C}")
print(f"C0 = {C0.shape}")
print(f"C0 = {C0}")
eig_t = la.eig(C, b = C0)
Этот фрагмент кода находится внутри функции gevp_jack(data,mask), которая должна выполнять этот GEVP для множества различных образцы складного ножа.
Когда я запускаю код, я получаю следующий результат:
Код: Выделить всё
C = (7, 7)
C = [[ 1.59584972 -2.15633651 1.24114058 1.75321492 -1.81777217 1.81941323
-0.91749864]
[-2.15633651 2.9590494 -1.68747421 -2.40047725 2.50849557 -2.51730532
1.25051207]
[ 1.24114058 -1.68747421 0.98367127 1.37224169 -1.40936567 1.40846551
-0.72515541]
[ 1.75321492 -2.40047725 1.37224169 1.9320236 -1.99770539 2.00577185
-1.01332363]
[-1.81777217 2.50849557 -1.40936567 -1.99770539 2.17348089 -2.16582443
1.08016084]
[ 1.81941323 -2.51730532 1.40846551 2.00577185 -2.16582443 2.15743968
-1.09213161]
[-0.91749864 1.25051207 -0.72515541 -1.01332363 1.08016084 -1.09213161
0.51369853]]
C0 = (7, 7)
C0 = [[ 5.09266872 -6.49228588 4.14126736 5.37497589 -4.90238238 5.82926292
-3.01593039]
[-6.49228588 8.46178084 -5.22826411 -6.92532952 6.49513817 -7.44136205
3.78233514]
[ 4.14126736 -5.22826411 3.40637298 4.36963407 -3.89903505 4.7350309
-2.4841818 ]
[ 5.37497589 -6.92532952 4.36963407 5.68667154 -5.23611244 6.14753923
-3.16321806]
[-4.90238238 6.49513817 -3.89903505 -5.23611244 5.28974258 -5.64769213
2.79528734]
[ 5.82926292 -7.44136205 4.7350309 6.14753923 -5.64769213 6.65394343
-3.42858045]
[-3.01593039 3.78233514 -2.4841818 -3.16321806 2.79528734 -3.42858045
1.80604997]]
Unexpected exception formatting exception. Falling back to standard exception
Traceback (most recent call last):
File "/home/andrea/anaconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 3526, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "/tmp/ipykernel_4321/229272726.py", line 2, in
eig, err_eig = gu.gevp_jack(data, mask)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andrea/Documents/[...]/gevp_utils.py", line 378, in gevp_jack
eig_t = np.sort(eig_t)
^^^^^^^^^^^^^^
File "", line 200, in sort
File "/home/andrea/anaconda3/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 1029, in sort
a = asanyarray(a).copy(order="K")
^^^^^^^^^^^^^
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (2, 7) + inhomogeneous part.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/andrea/anaconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 2120, in showtraceback
stb = self.InteractiveTB.structured_traceback(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py", line 1435, in structured_traceback
return FormattedTB.structured_traceback(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py", line 1326, in structured_traceback
return VerboseTB.structured_traceback(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py", line 1173, in structured_traceback
formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py", line 1088, in format_exception_as_a_whole
frames.append(self.format_record(record))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py", line 970, in format_record
frame_info.lines, Colors, self.has_colors, lvals
^^^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py", line 792, in lines
return self._sd.lines
^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
value = obj.__dict__[self.func.__name__] = self.func(obj)
^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/stack_data/core.py", line 698, in lines
pieces = self.included_pieces
^^^^^^^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
value = obj.__dict__[self.func.__name__] = self.func(obj)
^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/stack_data/core.py", line 649, in included_pieces
pos = scope_pieces.index(self.executing_piece)
^^^^^^^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
value = obj.__dict__[self.func.__name__] = self.func(obj)
^^^^^^^^^^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/stack_data/core.py", line 628, in executing_piece
return only(
^^^^^
File "/home/andrea/anaconda3/lib/python3.11/site-packages/executing/executing.py", line 164, in only
raise NotOneValueFound('Expected one value, found 0')
executing.executing.NotOneValueFound: Expected one value, found 0
Подробнее здесь: https://stackoverflow.com/questions/786 ... with-scipy