错误

AttributeError: module 'numpy' has no attribute 'bool'. np.bool was a deprecated alias for the builtin bool. To avoid this error in existing code, use bool by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.bool_ here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

分析

这个错误是由于 numpy 版本 1.20 及以上不再支持 np.bool,它已经被弃用并移除,应该改为使用 Python 内建的 boolnp.bool_ 来代替。

解决方法

但是我们不对代码进行修改,我们先对numpy进行降级。

conda install numpy=1.19

或者

pip install numpy==1.19

尝试安装 mxnet 的早期版本。

conda install mxnet=1.8.0

或者

pip install mxnet==1.8.0

接下来即可正常运行。

范例

import mxnet as mx
from mxnet import nd

# 初始化数组
x = nd.array([[1, 2], [3, 4]])

# 打印数组
print(x)

# 计算矩阵乘法
y = x * x.T
print(y)

返回结果:

[[1. 2.]
 [3. 4.]]
<NDArray 2x2 @cpu(0)>

[[ 1.  6.]
 [ 6. 16.]]
<NDArray 2x2 @cpu(0)>

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐