我有一个接受参数的函数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()
>>>
Run Code Online (Sandbox Code Playgroud)
正如你看到的,我不能申请len到P,因为它不是一个数组....有什么样isarray或isscalar在Python?
谢谢