“list”对象没有属性”shape”。

huangapple go评论76阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月17日 17:06:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270354.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定