PTVS 和 numpy System.Int64 转换中的 numpy 64 位支持 [英] numpy 64bit support in PTVS and numpy System.Int64 casting

查看:27
本文介绍了PTVS 和 numpy System.Int64 转换中的 numpy 64 位支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 IronPython 和 numpy 编写一些调用 .NET 程序集的代码.版本信息:numpy-2.0.0-1scipy-1.0.0-2IronPython 2.7.1

I am trying to write some code with IronPython and numpy that calls a .NET assembly. Version info: numpy-2.0.0-1 scipy-1.0.0-2 IronPython 2.7.1

我根据此处给出的说明安装了 scipy 和 numpy:

I installed scipy and numpy according to the instructions given here:

http://www.enthought.com/repo/.iron/

当我尝试使用 ipy64.exe 运行时,我得到以下信息:

When I try to run with ipy64.exe I get the following:

Failed while initializing NpyCoreApi: BadImageFormatException:An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000
B)
NumpyDotNet stack trace:
  at NumpyDotNet.NpyCoreApi.GetNativeTypeInfo(Int32& intSize, Int32& longsize, Int32& longLongSize, Int32& longDoubleSize)
  at NumpyDotNet.NpyCoreApi..cctor()

一切都通过 ipy.exe 运行.IronPython 的当前版本的 numpy 是否与 64 位不兼容?

Everything runs with ipy.exe. Is the current version of numpy for IronPython not 64-bit compatible?

我正在调查的根本问题(可能与上述有关,也可能无关)涉及调用需要 System.Int64 作为参数的 .NET 程序集方法.python 本机 int 工作正常,但是当使用 numpy.int32(在 ipy.exe 下)调用时,隐式转换失败:

The root problem I am investigating (may or may not be related to above) involves invoking a .NET assembly method that requires a System.Int64 as an argument. The python native int works fine but when invoking with a numpy.int32 (under ipy.exe) the implicit cast fails with:

E
======================================================================
ERROR: data_type_tests
   System.Array[Int64](listValues)
TypeError: expected Int64, got numpy.int32

我正在执行的代码是:

values = array([1,2,3,4,5])
listValues = list(values);
System.Array[Int64](listValues)

如果我直接列一个列表,即 values = [1,2,3,4,5]然后上面的运行.

If I make a list directly, i.e. values = [1,2,3,4,5] then the above runs.

关于将 numpy 数组转换为 32 位以下的 System.Array[Int64] 的任何建议或对 IronPython 上的 numpy 64 位支持状态的评论?

Any suggestions on converting the numpy array to a System.Array[Int64] under 32 bit or comments on the state of the numpy 64 bit support on IronPython?

推荐答案

我需要的是:

listValues.tolist() instead of list(listValues)

list() 方法将保留每个元素.这个论坛帖子有我正在寻找的答案:http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=2962&p=12102

the list() method will keep each element wrapped. This forum post had the answer I was looking for: http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=2962&p=12102

我仍然对 64 位 numpy 支持感到好奇?

I am still curious about the 64bit numpy support though?

这篇关于PTVS 和 numpy System.Int64 转换中的 numpy 64 位支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆