简体   繁体   English

我如何声明:new float [,] [,] {???}

[英]How I can declare that: new float[,][,] {???}

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... 我需要的是2dArray of float 2dArray ...

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 我确定这是可能的。.是否有锯齿...我需要一个解决方案...如果VS的Intellisense在下面没有给出带红色下划线的错误

new float[,][,]

that's tell me this exist in some way ... 告诉我这以某种方式存在...


I can accept a Collection alternative: 我可以接受Collection替代方法:

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: 呵呵,好奇的是...我需要一个LINQ.Zip()操作...我想要返回一个值,就像我将zip压缩成Python样式一样,将两个2dArray一起返回...我尝试了:

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 . 其中this.Biases是一个List<float[,]> ,与this.Weights相同。

But those tries got me error due to Cannot create an instance of the static class 'Tuple' 但是由于Cannot create an instance of the static class 'Tuple'这些尝试使我出错

Yes, it's about NN. 是的,关于NN。 I know that exist libs like Accord.Net, that new one from Microsoft CNTK, or TensorFlow, ... name it !!! 我知道存在像Accord.Net这样的库,是来自Microsoft CNTK或TensorFlow的新库,...把它命名! 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 ;) ) 尽可能少的外部库(鼓励我作为code'bro;))

I successed on this thing one step before (C#): 我在(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[]>(); 其中this.Sizes = List<float[]>(); and Math.Random.Rand2DArray(float x, float y, int dim1, int dim2); 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] . 返回尺寸为[dim1,dim2] xy (自定义静态函数)之间的Random float的[dim1,dim2] That give me the exact thing of (Python): 这给了我(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. 其中sizes = []npNumpy的Python库。

Hey guys, I'm facing the "Convert Python to C#" ... "non-typed to typed" language ;) HELP!!! 大家好,我正在面对“将Python转换为C#” ...“非类型化至类型化”语言;)帮助!

Just tell it the size... 告诉它大小...

var x = new float[3, 4][,];

That gives you a grid of 12 spaces for 2D arrays of floats. 这样就可以为12个浮点数数组提供12个空格的网格。 Each of the inner arrays can be any size you like. 每个内部数组可以是您喜欢的任何大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM