相关疑难解决方法(0)

如何确定Python中嵌套数据结构的类型?

我目前正在将一些 Python 翻译成 F#,特别是神经网络和深度学习

为了确保正确转换数据结构,需要 Python 中嵌套类型的详细信息。该类型()函数工作简单类型而不是嵌套类型。

例如在 Python 中:

> data = ([[1,2,3],[4,5,6],[7,8,9]],["a","b","c"])
> type(data)
<type 'tuple'>
Run Code Online (Sandbox Code Playgroud)

只给出第一级的类型。对元组中的数组一无所知。

我希望像 F# 那样做

> let data = ([|[|1;2;3|];[|4;5;6|];[|7;8;9|]|],[|"a";"b";"c"|]);;

val data : int [] [] * string [] =
  ([|[|1; 2; 3|]; [|4; 5; 6|]; [|7; 8; 9|]|], [|"a"; "b"; "c"|])
Run Code Online (Sandbox Code Playgroud)

返回独立于值的签名

int[][]*字符串[]

*         is a tuple item separator  
int [] [] is a two dimensional jagged array of int  
string [] is a one dimensional array of …
Run Code Online (Sandbox Code Playgroud)

python types

7
推荐指数
2
解决办法
2221
查看次数

标签 统计

python ×1

types ×1