Simple sigmoid function - why does it work on both scalars and arrays?

I’m right now doing the practice lab for week 3. I just finished the sigmoid function but I am confused why my syntax works for arrays and matrices, as it is.

I first made things more complicated than they should have been and started googling how to make a function work on both scalars and on arrays, and read about vectorizing functions, and about np.choose() etc. But it seems like the function in its most basic form, works perfectly.

Why is that? I think there is a very simple explanation for this. :slight_smile:
edit: I wasn’t sure if I could include my code here, so I didn’t

Hello @Rickard

Welcome to the communtiy.

This is because of the flexibility offered by numpy. In this case, we are using the numpy.exp() mathematical function inside our sigmoid function. This function will accept a scalar/array as an input. When input is a scalar, output will be a scalar. On the other hand, if the input is an array it will work on each element of the array and return an output array.

great, thank you very much!

You are most welcome @Rickard