question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add toArray1D<type>, toArray2D<type> etc.

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
dsymecommented, May 26, 2021

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.

1reaction
gbaydincommented, Jul 31, 2021

Implemented in #360

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found