None type object is not iterable

Hi team,
I am creating a tensor x and passing x as a parameter to a function f, while passing x as a parameter to a function f, I am getting an error TypeError: ‘NoneType’ object is not iterable
index = 20
x= torch.tensor([index])
y = f(x)
Please help me to resolve this issue.

Does the error occur inside of y = f(x) execution or before? The two first lines of your code work as expected for me.
When I get a TypeError: ‘NoneType’ object is not iterable, it is usually because I forget to write the return statement at the end of a function. In fact functions that return nothing actually return None.

error occurred while calling function f with x as parameter , and return statement is there at the end of function .

Can you print x just before calling y = f(x) and check that its value is tensor([20]) ? If the value of x is correct then I think the problem comes from function f. Could you provide the code of function f ?

yes, value of x is tensor([20]) before calling y = f(x) .