Comments (6)
Update: I have tried to dig into this issue by copying the slicing by string code over from NDarray.cs to figure out why it breaks down:
using Numpy;
using static Numpy.np;
using System.Numerics;
using Numpy.Models;
using Python.Runtime;
public static void numpy_test()
{
Python.Runtime.PythonEngine.Initialize();
NDarray arr = np.array(new float[]{ 1, 2, 3, 4, 5 });
var tuple = new PyTuple(Numpy.Models.Slice.ParseSlices("2:4").Select(s =>
{
if (s.IsIndex)
return new PyInt(s.Start.Value);
else
return s.ToPython();
}).ToArray());
var arr0 = new NDarray(arr.PyObject[tuple]);
Debug.Log("Numpy test passed.");
}
But this does not compile because "The type 'PyObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'Python.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd'."
But the most recent version of Python.Runtime available on NuGet is 2.5.2, which does have a definition for Python.Runtime.PyObject, as does Numpy.Models. Not sure what is going on here but will keep looking into it.
from numpy.net.
I just added a little test case with your code and it works perfectly in my test environment.
[TestMethod]
public void IssueByMegawattFs()
{
var arr = np.array(new int[] { 1, 2, 3, 4, 5 });
var slice0 = new Slice(2, 4);
var arr4 = arr[slice0];
Assert.AreEqual("array([3, 4])", arr4.repr);
var slice1 = new Slice(2, -1);
var arr5 = arr[slice1];
Assert.AreEqual("array([3, 4])", arr5.repr);
var arr1 = arr["2:4"];
Assert.AreEqual("array([3, 4])", arr1.repr);
var arr2 = arr[":4"];
Assert.AreEqual("array([1, 2, 3, 4])", arr2.repr);
var arr3 = arr[":-1"];
Assert.AreEqual("array([1, 2, 3, 4])", arr3.repr);
}
Here are the dependencies of my test project:
As you can see the difference is that Numpy references pythonnet 3.0.0-preview2022-04-11
I don't understand why yours uses Python.Runtime.dll version 2.5.2
. I'll make a test project with the nuget to see if there is something wrong with the numpy 3.10.1.30 nuget.
from numpy.net.
Have a look at the source code. I added a new SlicingExample for you which works just fine with the latest nuget
from numpy.net.
I see what happened:
I am using Unity, which is not compatible with NuGet. My process for adding Numpy to my project was as follows:
- Download the .nupkg directly from the NuGet website.
- Look under "Dependencies" on the NuGet page and download the .nupkg for all the dependencies
- Repeat step 2 with the NuGet page for all the dependencies until there are none left
- Extract the .nupkg files and add the .NET Standard 2 version of each package to my Unity project assets folder.
On the NuGet page for Numpy, Python.Runtime is not even listed as a dependency:
Therefore, I determined which version of Python.Runtime to use based on Python.Included, which lists Python.Runtime v2.5.2 as the minimum requirement and links to this download:
I see now that there is a version 3.0.0 available at https://www.nuget.org/packages/pythonnet/3.0.0-rc4. I will try that and see if it works. Maybe this version should be listed under dependencies for Numpy on the NuGet page?
Thank you for looking into this!
from numpy.net.
Never mind--I see now that I was using the wrong version of Python.Included (I got mixed up because NuGet linked me to the "latest" non-preview version of Python.Included from Numpy's dependency page, but I needed 3.10.0-preview2).
from numpy.net.
Correct ;). Closing this. Should you still have issues you can reopen.
from numpy.net.
Related Issues (20)
- Slow Conversion for 3D arrays HOT 3
- np.load of np.savez impossible to get values back out? HOT 3
- np.array leaks memory HOT 12
- Numpy hangs on exit since version 3.10.1.29 (last stable 3.7.1.28) HOT 7
- Support for CuPy HOT 1
- Please Sign and assign StrongName for Numpy Nuget package
- np.split HOT 12
- `Half` type arrays HOT 7
- Set conditions as NDArray Type HOT 3
- fft() failed: βindex -2 is out of bounds for axis 0 with size 1β HOT 9
- Problem with passing imaginery numbers HOT 3
- NDarray of DateTime HOT 3
- Azure AppService and System.DllNotFoundException: Could not load python311.dll with flags RTLD_NOW | RTLD_GLOBAL: python311.dll: cannot open shared object file: No such file or directory HOT 5
- Could not find platform dependent libraries <exec_prefix> HOT 6
- System.TypeLoadException: Could not load type 'Python.Runtime.PyLong' from assembly 'Python.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd'. HOT 5
- Numpy.Bare build for Python 3.11 HOT 3
- np.sum(NDArray, axis:1) not supported? HOT 5
- Unable to use Numpy.NET from linux environment HOT 1
- Hello, has SciSharp/NumSharp stopped development and maintenance? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from numpy.net.