ManimGL 运行出现 ValueError: operands could not be broadcast together with shapes (24,3) (0,3)

问题描述

ManimGL 运行出现 ValueError: operands could not be broadcast together with shapes (24,3) (0,3)

命令

manimgl start.py SquareToCircle

源码

from manimlib import *

class SquareToCircle(Scene):
def construct(self):
circle = Circle() # 创建一个圆
circle.set_fill(BLUE, opacity=0.5) # 设置圆的填充颜色和透明度
circle.set_stroke(BLUE_E, width=4) # 设置圆的边框颜色和宽度

    self.add(circle)  # 将圆添加到场景中
    self.wait(1)  # 等待1秒钟,以便可以观察动画

详细错误信息

PS F:\360MoveData\Users\A\Desktop\code\普通编程\python\动画\t> manimgl start.py SquareToCircle
ManimGL v1.6.1
[13:26:44] INFO     Using the default configuration file, which you can modify in `f:\360movedata\users\a\desktop\code\普通编程\python\动画\t\v\lib\site-packages\manimlib\default_config.yml`               config.py:265           INFO     If you want to create a local configuration file, you can create a file named `custom_config.yml`, or run `manimgl --config`                                                             config.py:266           WARNING  You may be using Windows platform and have not specified the path of `temporary_storage`, which may cause OSError. So it is recommended to specify the `temporary_storage` in the config config.py:232                    file (.yml)
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "F:\360MoveData\Users\A\Desktop\code\普通编程\python\动画\t\v\Lib\site-packages\manimlib\__main__.py", line 25, in main
    scene.run()
  File "F:\360MoveData\Users\A\Desktop\code\普通编程\python\动画\t\v\Lib\site-packages\manimlib\scene\scene.py", line 91, in run
    self.construct()
  File "F:\360MoveData\Users\A\Desktop\code\普通编程\python\动画\t\start.py", line 5, in construct
    circle = Circle()  # 创建一个圆
             ^^^^^^^^
  File "F:\360MoveData\Users\A\Desktop\code\普通编程\python\动画\t\v\Lib\site-packages\manimlib\mobject\geometry.py", line 324, in __init__
    Arc.__init__(self, 0, TAU, **kwargs)
  File "F:\360MoveData\Users\A\Desktop\code\普通编程\python\动画\t\v\Lib\site-packages\manimlib\mobject\geometry.py", line 218, in __init__
    VMobject.__init__(self, **kwargs)
  File "F:\360MoveData\Users\A\Desktop\code\普通编程\python\动画\t\v\Lib\site-packages\manimlib\mobject\types\vectorized_mobject.py", line 85, in __init__
    super().__init__(**kwargs)
    self.init_points()
  File "F:\360MoveData\Users\A\Desktop\code\普通编程\python\动画\t\v\Lib\site-packages\manimlib\mobject\geometry.py", line 221, in init_points
    self.set_points(Arc.create_quadratic_bezier_points(
  File "F:\360MoveData\Users\A\Desktop\code\普通编程\python\动画\t\v\Lib\site-packages\manimlib\mobject\types\vectorized_mobject.py", line 968, in wrapper
    if not np.all(self.get_points() == old_points):
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: operands could not be broadcast together with shapes (24,3) (0,3)

解决办法

安装 1.24版本的numpy

pip install numpy==1.24

解决来源

https://github.com/3b1b/manim/issues/2114

FexCode

Python中,当你尝试对两个数组进行操作时,如果它们的形状不兼容,就会出现"ValueError: operands could not be broadcast together with shapes"错误。这个错误通常发生在你尝试对形状不同的数组进行元素级别的操作时,比如加法、减法、乘法等。 要解决这个错误,你可以考虑以下几种方法: 1. 确保数组的形状相同:你可以使用NumPy库的reshape()函数来调整数组的形状,使其与另一个数组的形状相匹配。例如,如果你有一个形状为(2,)的数组和一个形状为(100,)的数组,你可以使用reshape()函数将第一个数组的形状调整为(2,1),然后再进行操作。 ```python import numpy as np array1 = np.array([1, 2]) array2 = np.array([1, 2, 3, ..., 100]) # 调整数组形状 array1_reshaped = array1.reshape((2, 1)) # 进行操作 result = array1_reshaped + array2 ``` 2. 使用广播功能:NumPy库提供了广播功能,可以自动调整数组的形状,使其与另一个数组的形状相匹配。你只需要确保数组的维度兼容即可。例如,如果你有一个形状为(2,)的数组和一个形状为(100,)的数组,你可以使用广播功能直接进行操作。 ```python import numpy as np array1 = np.array([1, 2]) array2 = np.array([1, 2, 3, ..., 100]) # 进行操作 result = array1 + array2 ``` 3. 检查数组的形状:在出现这个错误时,你可以检查一下两个数组的形状,确保它们是你期望的形状。你可以使用NumPy库的shape属性来获取数组的形状。 ```python import numpy as np array1 = np.array([1, 2]) array2 = np.array([1, 2, 3, ..., 100]) # 检查数组形状 print(array1.shape) # 输出:(2,) print(array2.shape) # 输出:(100,) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值