0

I have created the following function:

def c_min(a,b):
    result= [x - y for x in a for y in b]
    min=np.min(result)
    return min

I have created a test file with two lists:

a=[1,2,3] and b=[4,5,6]

When I running the function I get the correct result.

However when I run the function in my initial code I have the aforementioned in the title error. Have to be noted that the function in the initial code is applied in two arrays. One has size 1 and it is numpy.float64,the other 3 and it is numpy.ndarray. Why it can be applied to list and not in the arrays?

2
  • 1
    Can you post the inputs that are raising this error? Commented Nov 5, 2014 at 13:09
  • you can't iterate scalars Commented Nov 5, 2014 at 13:15

2 Answers 2

1

Both a and b need to be numpy.ndarray. If one of them is a scalar, the for ... in ... construct will fail.

Sign up to request clarification or add additional context in comments.

Comments

0

As mentioned in the post using the numpy.arrayor numpy.ndarraythe problem can be solved.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.