模块' ants'没有属性' from_numpy'

发布于 2025-02-11 01:57:56 字数 581 浏览 1 评论 0原文

我正在jupyter笔记本上工作,并使用pip安装蚂蚁领域:

pip install antspyx

但是,使用函数from_numpy引发错误:

import ants

Im2Use=Im[0,:,:,:]
fixed, moving, mytx=reg(Im2Use, t_rz)
fwdtransforms=mytx['fwdtransforms']
fixed_ants= ants.from_numpy(Im2Use.astype(float))
moving_ants= ants.from_numpy(t_rz.astype(float))
mywarpedimage=ants.apply_transforms( fixed=fixed_ants, moving=moving_ants,transformlist=fwdtransforms)

AttributeError: module 'ants' has no attribute 'from_numpy'

如何解决此问题?我还尝试使用导入蚂蚁导入蚂蚁。from_numpy,但这无效。

I am working in a jupyter notebook, and used pip to install ANTsPy:

pip install antspyx

However, using the function from_numpy throws an error:

import ants

Im2Use=Im[0,:,:,:]
fixed, moving, mytx=reg(Im2Use, t_rz)
fwdtransforms=mytx['fwdtransforms']
fixed_ants= ants.from_numpy(Im2Use.astype(float))
moving_ants= ants.from_numpy(t_rz.astype(float))
mywarpedimage=ants.apply_transforms( fixed=fixed_ants, moving=moving_ants,transformlist=fwdtransforms)

AttributeError: module 'ants' has no attribute 'from_numpy'

How can I solve this? I've also tried importing ants using import ants.from_numpy, but that did not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

脸赞 2025-02-18 01:57:56

如果您负责激活Virtualenv,请指定您的IDE+吗?

无论如何,这里是确保python模块预测安装在虚拟环境中的步骤:

  1. 中创建虚拟env
  2. python3 -m venv env_name:这将在您的当前路径source> source incouse env/bin 在Windows上仅在CD中激活您的Env Name
  3. /activate :这将激活您的虚拟env(如果 选择解释器,然后转到您创建的Env
  4. ,现在我们拥有虚拟环境,只需点击pip install antspyx,然后使用pip list 检查您的终端中,如果该软件包是在软件包中安装的,
  5. 如果 安装了该软件包,您仍然有错误重新启动您的IDE

Can you please specify your IDE+ if you took care of activating the virtualenv?

Anyways here are the steps to make sure that the python module is propoerly installed in your virtual environment :

  1. python3 -m venv env_name : this will create a virtual env in your current path
  2. source env/bin/activate : this will activate your virtual env (if on windows just cd into activate within your env name .\env\Scripts\activate
  3. If your using vscode hit ctrl+shift+p then select interpreter then go to your created env
  4. now we have our virtual environment just hit pip install antspyx then check with pip list and see in your terminal if the package is propoerly installed
  5. If you still have the error restart your IDE
季末如歌 2025-02-18 01:57:56

您是否尝试过:

from ants import from_numpy

have you tried:

from ants import from_numpy
下雨或天晴 2025-02-18 01:57:56

在这种情况下,问题是Scipy版本控制。我从版本1.7.3降级到1.2.0版,然后解决了问题。为什么?这是因为蚂蚁库期望在scipy.misc中使用一个称为“阶乘”的功能,但版本1.7.3移动了阶乘的位置。

The issue in this case was scipy versioning. I downgraded from version 1.7.3 to version 1.2.0, which then solved the problem. Why? It's because ants library expects a function called "factorial" in scipy.misc, but version 1.7.3 moved the location of factorial.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文