python: how to identify if a variable is an array or a scalar

后端 未结 14 1334
半阙折子戏
半阙折子戏 2020-12-22 16:13

I have a function that takes the argument NBins. I want to make a call to this function with a scalar 50 or an array [0, 10, 20, 30].

14条回答
  •  天涯浪人
    2020-12-22 16:51

    You can check data type of variable.

    N = [2,3,5]
    P = 5
    type(P)
    

    It will give you out put as data type of P.

    
    

    So that you can differentiate that it is an integer or an array.

提交回复
热议问题