【发布时间】:2013-05-24 07:22:44
【问题描述】:
我有一个接受参数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()
>>>
如您所见,我不能将len 应用于P,因为它不是一个数组.... python 中有类似isarray 或isscalar 的东西吗?
谢谢
【问题讨论】:
-
你试过测试它的
type吗?
标签: python arrays variables scalar