Q:

How to get the dimension of a function return value without evaluating the function

Assume I know that the function f returns a vector of unknown dimension. The function returns value of the form: np.array(list). Can I get the dimension of the return value without evaluating the function? 
Consider for instance this function:
def f(x):
    f1 = x**2
    f2 = x
    return np.array([f1,f2]);

I want some something like: dim(f) that gives the answer 2.
Right now I get around the problem by evaluating the function for a random  number and then find the dimension: len(f(np.random.rand()))
but I want to avoid the evaluation of the function.
npis off course numpy

A:

What Koen Dercksen said is correct, there is no way to determine the dimension of the result without evaluating the function. However, if you do evaluate the function, you should use the .shape property instead of len()
For example:
def f(x):
    f1 = x**2
    f2 = x
    return np.array([f1,f2]);

len = f(0).shape[0]

Also generating a new random number for the function call is unnecessary, you can pass a constant as the parameter and the result will be the same. 

