将任何多维 numpy 数组转换为元组元组的元组......维数不可知

Convert any multi-dimensional numpy array to tuple of tuples of tuples... agnostic of number of dimensions

只提供 tuple(tuple(i) for i in a[:,0,:]) 表明这不存在,但我正在寻找类似于 .totuple() 类似于 numpy 的 [=12] 的方法=]因为你不需要事先知道维数来生成元组的元组...

根据我的需要,这仅适用于浮点数或整数数组。

您可以使用递归函数转换为独立于维数的元组:

def totuple(a):
    try:
        return tuple(totuple(i) for i in a)
    except TypeError:
        return a

在这个答案中找到: Convert numpy array to tuple