问题
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
I installed scipy and numpy according to the instructions given here:
http://www.enthought.com/repo/.iron/
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()
Everything runs with ipy.exe. Is the current version of numpy for IronPython not 64-bit compatible?
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
The code I am executing is:
values = array([1,2,3,4,5])
listValues = list(values);
System.Array[Int64](listValues)
If I make a list directly, i.e. values = [1,2,3,4,5] then the above runs.
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?
回答1:
What I needed was:
listValues.tolist() instead of list(listValues)
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
I am still curious about the 64bit numpy support though?
来源:https://stackoverflow.com/questions/9182735/numpy-64bit-support-in-ptvs-and-numpy-system-int64-casting