【发布时间】:2018-12-23 10:51:30
【问题描述】:
我不知道如何声明(自知):
var x = new float[,][,] {???};
我需要的是一个 2dArray of 2dArray of float...
float[float[,],float[,]];
// or
float[[,],[,]];
也许
new float[new float[,], new float[,]] {???};
我确定这是可能的……锯齿状与否……我需要一个解决方案…… 如果VS的Intellisense在
下没有给出红色下划线的错误new float[,][,]
这告诉我这以某种方式存在......
我可以接受 Collection 替代方案:
new Tuple<float[,], float[,]>();
哦,你的好奇...我需要它来进行 LINQ.Zip() 操作...我希望返回一个值,例如,如果我将 zip 压缩为 Python 样式,则将两个 2dArray 放在一起...我试过了这个:
var x = this.Biases.Zip(this.Weights, (b, w) => new Tuple(new List<float[,](b), new List<float[,](w)));
和
var x = this.Biases.Zip(this.Weights, (b, w) => new Tuple(new List<float[,](), new List<float[,]()) = new Tuple<float[,],float[,]>());
其中this.Biases 是List<float[,]> 和this.Weights 相同。
但由于Cannot create an instance of the static class 'Tuple',这些尝试让我出错
是的,是关于 NN 的。我知道存在像 Accord.Net 这样的新库 来自 Microsoft CNTK 或 TensorFlow 的一个......命名它!我是那种 喜欢用我使用的语言做香草风格的人; 尽可能少的外部库(鼓励我作为代码'兄弟;))
我在这件事上取得了成功(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[,]>();
this.Sizes = List<float[]>();
和Math.Random.Rand2DArray(float x, float y, int dim1, int dim2); 在x 和y(自定义静态函数)之间返回一个2dArray 随机浮点数,维度为[dim1,dim2]。
这给了我(Python)的确切内容:
self.weights = [np.random.randn(y, x) for x, y in zip(sizes[:-1], sizes[1:])]
其中sizes = [] 和np 是Numpy 的Python 库。
大家好,我正面临“将 Python 转换为 C#”...“非类型化为类型化”语言;) 救命!!!
【问题讨论】:
-
数组在创建时需要 .NET/C# 中的大小(即使用
new)。未提供大小,因此new float[..]无效。 (数组type不需要大小,只需要创建。)
标签: c# arrays collections neural-network