I can't figure out how to declare that (for self-knowledge):
var x = new float[,][,] {???};
What I need is a 2dArray of 2dArray of float...
float[float[,],float[,]];
// or
float[[,],[,]];
maybe
new float[new float[,], new float[,]] {???};
I'm sure it's possible.. jagged or not... I need a solution ... If the Intellisense of VS don't give a red underlined error under
new float[,][,]
that's tell me this exist in some way ...
I can accept a Collection alternative:
new Tuple<float[,], float[,]>();
Oh for the curious of you ... I need that for a LINQ.Zip() operation ... I want that return a value like if I zip ,to the Python style, two 2dArray together ... I tried this:
var x = this.Biases.Zip(this.Weights, (b, w) => new Tuple(new List<float[,](b), new List<float[,](w)));
and
var x = this.Biases.Zip(this.Weights, (b, w) => new Tuple(new List<float[,](), new List<float[,]()) = new Tuple<float[,],float[,]>());
where this.Biases
is a List<float[,]>
and same for this.Weights
.
But those tries got me error due to Cannot create an instance of the static class 'Tuple'
Yes, it's about NN. I know that exist libs like Accord.Net, that new one from Microsoft CNTK, or TensorFlow, ... name it !!! I'm the kind of guy that love to do it vanilla style from the language that I use; less extern lib that possible (encourage me as a code'bro ;) )
I successed on this thing one step before (C#):
this.Weights = this.Sizes.Take(this.Sizes.Count - 1).Zip(this.Sizes.Skip(1), (x, y) => new int[] {y, x}).Select(layer => NNGA.Math.Random.Rand2DArray(-2f, 2f, layer[0], layer[1])).ToList<float[,]>();
where this.Sizes = List<float[]>();
and Math.Random.Rand2DArray(float x, float y, int dim1, int dim2);
return a 2dArray of Random float between x
and y
(custom static function) of dimension [dim1,dim2]
. That give me the exact thing of (Python):
self.weights = [np.random.randn(y, x) for x, y in zip(sizes[:-1], sizes[1:])]
where sizes = []
and np
as Numpy
's Python library.
Hey guys, I'm facing the "Convert Python to C#" ... "non-typed to typed" language ;) HELP!!!
Just tell it the size...
var x = new float[3, 4][,];
That gives you a grid of 12 spaces for 2D arrays of floats. Each of the inner arrays can be any size you like.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.