[英]Python to C# multidimensional array
I need to translate this snippet from python to c#:我需要将此片段从 python 翻译为 c#:
def _get_w_matrix(quaternions):
w_matrix = [[[q[3], q[2], -q[1], q[0]],
[-q[2], q[3] , q[0], q[1]],
[q[1], -q[0], q[3], q[2]],
[-q[0], -q[1], -q[2], q[3]]] for q in quaternions]
where quaternions is something like四元数类似于
[[0. 0. 0. 0.]
[0. 2. 2. 0.]
[2. 3. 1. 0.]]
I don't understand which type of object is returned and how to write it down.我不明白返回的是哪种类型的 object 以及如何写下来。
EDIT: I'm using Numpy for .NET, so in my c# code the variable quaternion is of type NDarray.编辑:我将 Numpy 用于 .NET,所以在我的 c# 代码中,变量四元数是 NDarray 类型。
The Python type()
function combined with the print()
function are two functions you can use for debugging the look and type of the w_matrix list
. Python type()
function 结合print()
function 是两个可用于调试w_matrix list
的外观和类型的函数。
I wrote this code for debugging purposes:我为调试目的编写了这段代码:
def _get_w_matrix(quaternions):
w_matrix = [[[q[3], q[2], -q[1], q[0]],
[-q[2], q[3] , q[0], q[1]],
[q[1], -q[0], q[3], q[2]],
[-q[0], -q[1], -q[2], q[3]]] for q in quaternions]
return w_matrix
inputMatrix = [[0,0,0,0],
[0,2,2,0],
[2,3,1,0]]
test = _get_w_matrix(inputMatrix)
print("matrix created by function: ")
print(test)
print("type of matrix:")
print(type(test))
which returns:返回:
matrix created by function:
[[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 2, -2, 0], [-2, 0, 0, 2], [2, 0, 0, 2], [0, -2, -2, 0]], [[0, 1, -3, 2], [-1, 0, 2, 3], [3, -2, 0, 1], [-2, -3, -1, 0]]]
type of matrix:
<class 'list'>
The type is a python list of list of list with integers.该类型是带有整数的列表列表的 python 列表。 I am not an expert at c# but that should correspond to something like List<List<List>>>我不是 c# 的专家,但这应该对应于类似 List<List<List>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.