Add toArray1D<type>, toArray2D<type> etc.
See original GitHub issueI have been trying to incorporate diffsharp into an existing codebase which is based on Math.NET Numerics
but I am having trouble with getting standard vectors
and matrices
from diffsharp tensors
. My intention is to check correctness of current calculations with diffsharp.
let t1 = dsharp.tensor [ 0.0 .. 0.2 .. 1.0 ]
let a = t1.toArray()
This returns System.Array
which is incompatible with 'a [ ]
for some reason.
Is there a way to get typed F# arrays (or 2d arrays) from tensors? A good example to what I need would be that tensorflow
can return ndarray
from tensors.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Store different datatypes in one NumPy array?
I have two different arrays, one with strings and another with ints. I want to concatenate them, into one array where each column...
Read more >Data type objects (dtype)
A data type object (an instance of numpy.dtype class) describes how the bytes in the fixed-size block of memory corresponding to an array...
Read more >Array creation — NumPy v1.25 Manual
When you use numpy.array to define a new array, you should consider the dtype of the elements in the array, which can be...
Read more >Change data type of given numpy array
Problem #1 : Given a numpy array whose underlying data is of 'int32' type. Change the dtype of the given object to 'float64'...
Read more >4. NumPy Basics: Arrays and Vectorized Computation
Copies the input data by default. Like the built-in range but returns an ndarray instead of a list. Produce an array of all...
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
It returns a System.Array, which can then be downcast to the right kind of array
The exact type of the array is the natural .NET corresponding type for the element type of tensor, seen here for example: https://github.com/DiffSharp/DiffSharp/blob/c1d7eb613539cae3ae11a7cca4df230503ef84e0/src/DiffSharp.Backends.Torch/Torch.RawTensor.fs#L222
If we add
.toArray1D<float>()
,toArray2D<int64>()
etc. I guess they will do the job of casting to the requested element type before delivering the results.Implemented in #360