我有一个接受参数NBins
的函数。我想使用标量50
或数组[0, 10, 20, 30]
调用此函数。如何在函数中识别NBins
的长度?或者换一种说法,它是一个标量还是一个向量?
我试过这个:
>>> N=[2,3,5]
>>> P = 5
>>> len(N)
3
>>> len(P)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'int' has no len()
>>>
如您所见,我不能对P
应用len
,因为它不是一个数组……在python中有像isarray
或isscalar
这样的东西吗?
谢谢
https://stackoverflow.com/questions/16807011
复制相似问题