Can numpy.net convert ndarray to Array type?
See original GitHub issueIf ndarray has N dimensions, it will be very troublesome to restore it to T[,]. Maybe numpy.net can use implicit operators to convert ndarray to Array type. https://learn.microsoft.com/en-us/dotnet/api/system.array?view=net-7.0 https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/user-defined-conversion-operators
This way I can easily convert ndarray to torch.tensor🤣 https://github.com/dotnet/TorchSharp/blob/c55e9f535aa46c4dfa104d839019553b693616c0/src/TorchSharp/Tensor/Tensor.Factories.cs#L2654
int[,,] a = new int[3, 5, 7];
Array b = a;
Tensor c = as_tensor(b);
Console.WriteLine(c);
// [3x5x7], type = Int32, device = cpu
Issue Analytics
- State:
- Created 9 months ago
- Comments:12
Top Results From Across the Web
HOW to change NDArray to C#'s int[] · Issue #40
To work with data from C# in Numpy it has to be copied into the Python engine by using np.array(...) . You get...
Read more >numpy.ndarray.astype — NumPy v1.25 Manual
Copy of the array, cast to a specified type. Parameters: dtypestr or dtype. Typecode or data-type to which the array is cast. order{'C',...
Read more >c# - Numpy.NET Getting Values
The problem is, I can't convert my NDarrays to C# arrays to use the values. I tried this method (in README - section...
Read more >SciSharp/Numpy.NET: C#/F# bindings for ...
NET: C#/F# bindings for NumPy - a fundamental library for scientific computing ... The alternative is to cast value types to an array...
Read more >Change data type of given numpy array
Solution : We will use numpy.astype() function to change the data type of the underlying data of the given numpy array.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I figured out how to use your sample function. It does eliminate several hundred lines of redundant code. See it in the new release.
thank you!
I did not get an email on this comment like I usually do. It is lucky that I checked these boards this morning.
Internally, Numpy stores all arrays as single dimension arrays. When you add a shape to it, you are just adjusting some internal values that make it appear to be multi-dimensional.
Are you suggesting that we add something like this to the library? It would have to be expanded to include all 16 datatypes. If we make it work for 5 dimensions, that is 64 separate explicit operators.
Can you think of an easier way to do this?
The code to call them would look like this: