我想使用pythonnet软件包从Python初始化一个.NET锯齿状数组。对于一维数组,我可以这样:
import clr
from System import Array
a = Array[int]([1, 2, 3])
但是我该如何处理锯齿状数组?因此,假设我在python中有以下列表列表:
[[1, 2, 3], [4, 5, 6]]
在C#中,我会那样做:
int[][] a = new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }};
答案 0 :(得分:1)
在Python中可以这样完成:
<label id="searcHResults" aria-live="polite" for="myinput" aria-atomic="true">
<span id="updateme">{numResults}</span>
search results were found
</label>
或者如果您定义了辅助函数:
b = Array[Array[int]]([Array[int]([1,2,3]), Array[int]([4,5,6])])
然后可以用作:
def asnetarray(x, defaulttype):
if type(x) is list:
if any([type(xi) is list for xi in x]):
# Array of array
return asnetarray([asnetarray(xi, defaulttype) for xi in x], defaulttype)
elif x:
# Array
return Array[type(x[1])](x)
else:
# Empty array
return Array[defaulttype]([])
else:
# Single element
return Array[type(x)]([x])