当前位置: 首页 > news >正文

报错 raise AttributeError(__former_attrs__[attr], name=None) AttributeError: module ‘numpy‘ has no att

报错

raise AttributeError(former_attrs[attr], name=None)
AttributeError: module ‘numpy’ has no attribute ‘int’.
np.intwas a deprecated alias for the builtinint. To avoid this error in existing code, useintby itself. Doing this will not modify any behavior and is safe. When replacingnp.int, you may wish to use e.g.np.int64ornp.int32to specify the precision. If you wish to review your current use, check the release note link for additional information.
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.int 被正式弃用了,而在 NumPy 2.0+ 之后,这个属性被彻底移除了。代码中使用的 np.int 实际上就是 Python 原生的 int。

解决方法:

修改文件中报错的那几行代码;我的是在datasets.py中报错。
bi_rgb = np.floor(np.arange(n_rgb) / batch_size).astype(np.int) # batch index
改为bi_rgb = np.floor(np.arange(n_rgb) / batch_size).astype(int) # 或者用 np.int64
可以直接查找.astype(np.int)替换为 .astype(int);
.astype(np.float) 替换为.astype(float)
.astype(np.bool) 替换为.astype(bool)

np.int16, np.int32, np.int64, np.float32, np.uint8这种带有数字后缀的类型,全部保留,不用修改。
只有单独的 np.int, np.float, np.bool 才需要改成 int, float, bool。
因为np.int 这种简写被废弃了。而 np.int16 属于 NumPy 的明确精度类型(Explicit Precision Types)。
np.int (报错): 这是 Python 内置 int 的别名,NumPy 2.0 删除了它,要求直接用 int。
np.int16 (正常): 这是 NumPy 特有的 16 位整数类型,它在处理图像数据(比如像素值 0-255)时非常常用,在所有 NumPy 版本中都是合法且推荐的。

http://www.cnnetsun.cn/news/2129055.html

相关文章:

  • 深入解析OpCore-Simplify:如何通过模块化架构实现OpenCore EFI自动化配置
  • Windows系统臃肿症如何根治?Win11Debloat的深度净化方案
  • 别再乱用ifconfig了!RK3588 Ubuntu 20.04网络配置保姆级指南(NetworkManager vs netplan)
  • 从AMBA CHI的Link层设计,聊聊芯片互连中的“流量控制”那些事儿
  • 组件化技术前端组件库与设计系统的建设维护方法
  • 报错 _pickle.UnpicklingError: unpickling stack underflow 这个错误,通常意味着 .cache 缓存文件已经损坏。
  • L5190,L3118,L3158,L3166,L3169,L5198,L351,L353,L355,L358,L550,L551,L555清零,提示“打印机中的废墨垫已到使用寿命”亲测有用。
  • 3步掌握Charticulator:从数据到专业图表的免费完整指南
  • 终极内存故障排查指南:Memtest86+ 完整实战方案
  • 一站式游戏模组管理器:XXMI Launcher终极完整指南
  • 3步搭建Windows流媒体服务器:Nginx-RTMP-Win32终极指南
  • 如何高效构建Dify工作流:7个实战模板完全指南
  • VA在汽车动力电池模组全流程检测中的应用(3)
  • 如何完整保存微信聊天记录?WeChatMsg终极解决方案指南
  • PoeCharm:流放之路玩家的终极BD构建优化指南
  • 一篇搞定2026年简历模板服务商选购,避坑+选品全说清
  • CAN总线——硬实时的设计哲学:用一半带宽换来的确定性
  • Win11Debloat:Windows 11终极优化指南 - 一键清理系统臃肿
  • Java医疗系统过等保四级失败率高达68%?揭秘3个被监管机构高频扣分的Spring Security配置盲区
  • 别再死记硬背BN公式了!用Python手搓一个BatchNorm层,彻底搞懂训练和测试的区别
  • Windows系统优化神器:3分钟告别臃肿,让你的Windows重获新生
  • 如何优雅管理微信社交圈:WechatRealFriends帮你告别单向好友烦恼
  • 5大核心功能解密:unrpa如何成为RPA文件提取的终极解决方案
  • 告别龟速握手!实测对比TLS 1.2与TLS 1.3在Nginx/OpenSSL上的性能差异
  • InlineSVGToAI:打破SVG代码到矢量图形的工作流壁垒
  • OpenModScan:工业级Modbus调试工具实战指南
  • 终极指南:如何使用VideoDownloadHelper轻松下载网页视频
  • 混合云环境中UG/NX许可证部署与管理策略
  • 第三方许可证分点平台与Windchill系统无缝集成方案
  • 零基础学会Appium自动化测试