程序报错“Warning (from warnings module): File "C:/Users/阿娅/Desktop/计算物理/16.11.py", line 24 T[0, n] = 10 + 12 * np.sin(2 * np.pi * n * dt / T) RuntimeWarning: divide by zero encountered in divide Warning (from warnings module): File "C:/Users/阿娅/Desktop/计算物理/16.11.py", line 24 T[0, n] = 10 + 12 * np.sin(2 * np.pi * n * dt / T) RuntimeWarning: invalid value encountered in sin TypeError: only size-1 arrays can be converted to Python scalars The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:/Users/阿娅/Desktop/计算物理/16.11.py", line 24, in <module> T[0, n] = 10 + 12 * np.sin(2 * np.pi * n * dt / T) ValueError: setting an array element with a sequence.”
时间: 2024-04-03 17:30:32 浏览: 91
这个错误看起来是由于在程序中使用了除以零的表达式,导致了一个无效的数值。请检查第24行代码,看看是否有可能在计算中除以了一个变量T的值为0的情况。同时,你也可以检查一下代码中是否有使用到np.sin()的地方,并确认输入的参数是否正确。最后,你可以看看程序中是否有试图将一个序列赋值给一个数组元素的情况。希望这些提示能帮到你!
相关问题
Warning (from warnings module): File "C:/Users/liang/Desktop/python作业/14.py", line 34 mypoint.set_data([x[i],y[i]]) MatplotlibDeprecationWarning: Setting data with a non sequence type is deprecated since 3.7 and will be remove two minor releases later
这个警告是说在 Matplotlib 3.7 版本及以后的版本中,使用非序列类型的数据设置函数 `set_data()` 已经被弃用,将在两个次要版本之后被移除。因此,建议使用序列类型的数据设置函数。可以将代码中的 `set_data()` 改为 `set_xdata()` 和 `set_ydata()`。修改后的代码如下:
``` python
def animate(i):
mypoint.set_xdata(x[i])
mypoint.set_ydata(y[i])
myline.set_xdata(x[:i])
myline.set_ydata(y[:i])
return mypoint, myline
```
这样就可以避免警告信息的出现。
python detect.py /usr/lib/python3/dist-packages/pkg_resources/__init__.py:1235: UserWarning: /home/ucar/.cache/Python-Eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable). warnings.warn(msg, UserWarning) Downloading https://ultralytics.com/assets/Arial.ttf to /home/ucar/.config/Ultralytics/Arial.ttf... Traceback (most recent call last): File "/home/ucar/yolov3-9.6.0/utils/plots.py", line 58, in check_font return ImageFont.truetype(str(font) if font.exists() else font.name, size) File "/usr/local/lib/python3.6/dist-packages/PIL/ImageFont.py", line 655, in truetype return freetype(font) File "/usr/local/lib/python3.6/dist-packages/PIL/ImageFont.py", line 652, in freetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "/usr/local/lib/python3.6/dist-packages/PIL/ImageFont.py", line 194, in __init__ font, size, index, encoding, layout_engine=layout_engine OSError: cannot open resource During handling of the above exception, another exception occurred: Traceback (most recent call last): File "detect.py", line 30, in <module> from models.common import DetectMultiBackend File "/home/ucar/yolov3-9.6.0/models/common.py", line 25, in <module> from utils.plots import Annotator, colors, save_one_box File "/home/ucar/yolov3-9.6.0/utils/plots.py", line 70, in <module> class Annotator: File "/home/ucar/yolov3-9.6.0/utils/plots.py", line 72, in Annotator check_font() # download TTF if necessary File "/home/ucar/yolov3-9.6.0/utils/plots.py", line 64, in check_font return ImageFont.truetype(str(font), size) File "/usr/local/lib/python3.6/dist-packages/PIL/ImageFont.py", line 655, in truetype return freetype(font) File "/usr/local/lib/python3.6/dist-packages/PIL/ImageFont.py", line 652, in freetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "/usr/local/lib/python3.6/dist-packages/PIL/ImageFont.py", line 194, in __init__ font, size, index, encoding, layout_engine=layout_engine OSError: cannot open resource
这个错误看起来是在运行`detect.py`时出现的。根据错误信息,似乎是由于缺少字体文件`Arial.ttf`导致的。可以尝试使用以下命令下载该字体文件:
```
mkdir -p /home/ucar/.config/Ultralytics && \
cd /home/ucar/.config/Ultralytics && \
wget https://ultralytics.com/assets/Arial.ttf
```
如果您已经下载过该字体文件,那么可能是权限问题导致程序无法访问该文件。可以检查一下该文件的读写权限是否正确设置。另外,如果您是在服务器上运行程序,可能需要使用`sudo`命令以管理员身份运行。
阅读全文