英文:
the question of 'list' object has no attribute 'shape'
问题
我尝试使用这个代码(https://github.com/phillipiv/rssi-filtering-kalman)来测试卡尔曼滤波,但遇到了一些问题。
运行后,显示了这个错误。
如何修复它?
请给我一些建议。
(我尝试将 lenght = np.shape(signals)[1]
更改为 lenght = np.shape(np.array(signals))[1]
,AttributeError
消失了,但 ValueError
仍然存在。)
英文:
I tried to use this code (https://github.com/phillipiv/rssi-filtering-kalman) to test Kalman filtering, but encountered some issues.
After I ran it, it displayed this error.
How can I fix it?
Give me some advice please.
(I tried to change lenght = np.shape(signals)[1]
to lenght = np.shape(np.array(signals))[1]
, and the AttributeError
disappeared, but ValueError
still exists.)
File "C:\Users\fan\rssi-filtering-kalman\venv\Lib\site-packages\numpy\core\fromnumeric.py", line 2033, in shape
result = a.shape
^^^^^^^
AttributeError: 'list' object has no attribute 'shape'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\fan\rssi-filtering-kalman\scripts\main.py", line 32, in <module>
plot_signals([signal, signal_gray_filter, signal_fft_filter, signal_kalman_filter, signal_particle_filter],
File "C:\Users\fan\rssi-filtering-kalman\scripts\util.py", line 22, in plot_signals
lenght = np.shape(signals)[1] # time lenght of original and filtered signals
^^^^^^^^^^^^^^^^^
File "<__array_function__ internals>", line 200, in shape
File "C:\Users\fan\rssi-filtering-kalman\venv\Lib\site-packages\numpy\core\fromnumeric.py", line 2035, in shape
result = asarray(a).shape
^^^^^^^^^^
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (5, 199) + inhomogeneous part.
答案1
得分: 1
你需要将你的 a
转换为一个 numpy 数组。
a
是一个列表。
import numpy as np
a = [1, 2, 3]
try:
a.shape # 不起作用
except AttributeError:
print("没有 .shape 属性")
a = np.array(a)
# 尝试
a.shape # 起作用
英文:
You need to cast your a
to a numpy array.
a
is a list.
import numpy as np
a = [1,2,3]
try:
a.shape # doesn't work
except AttributeError:
print("No .shape attribute")
a = np.array(a)
# try
a.shape # works
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论