Implement Sigmoid in NumPy
Implement Sigmoid in NumPy
Implement the sigmoid activation function:
σ(x)=1+e−x1Examples
Input: x = [0, 2, -2]
Output: [0.5, 0.88079708, 0.11920292]
Input: x = 0
Output: 0.5
Input: x = [[-1, 0], [1, 2]]
Output: [[0.26894142, 0.5], [0.73105858, 0.88079708]]
Hint 1
Convert the input into a NumPy array so that operations like -x and np.exp(-x) work correctly for scalars, lists, and arrays.
Hint 2
Use np.asarray(x, dtype=float)
Requirements
- Must work on scalars, Python lists, and NumPy arrays
- Must return a NumPy array of floats
- Should be vectorized (no Python loops)
Constraints
- Vectorized implementation only
- Time limit: 200 ms; Memory: 64 MB
- Allowed library: NumPy only
Log in to take notes on this problem
Accepts: any
Implement Sigmoid in NumPy
Implement Sigmoid in NumPy
Implement the sigmoid activation function:
σ(x)=1+e−x1Examples
Input: x = [0, 2, -2]
Output: [0.5, 0.88079708, 0.11920292]
Input: x = 0
Output: 0.5
Input: x = [[-1, 0], [1, 2]]
Output: [[0.26894142, 0.5], [0.73105858, 0.88079708]]
Hint 1
Convert the input into a NumPy array so that operations like -x and np.exp(-x) work correctly for scalars, lists, and arrays.
Hint 2
Use np.asarray(x, dtype=float)
Requirements
- Must work on scalars, Python lists, and NumPy arrays
- Must return a NumPy array of floats
- Should be vectorized (no Python loops)
Constraints
- Vectorized implementation only
- Time limit: 200 ms; Memory: 64 MB
- Allowed library: NumPy only
Log in to take notes on this problem
Accepts: any