All problems
Quadratic Features
Problem
Build degree-2 polynomial features for a single variable: each row is [x_i, x_i^2].
Return the list of rows; empty input returns [].
Hint
Emit the original value and its square for each input.
Test cases
case 1
in: [[1,2,3]]
expected: [[1,1],[2,4],[3,9]]
case 2
in: [[-2,0,2]]
expected: [[-2,4],[0,0],[2,4]]
case 3
in: [[0.5]]
expected: [[0.5,0.25]]
case 4
in: [[]]
expected: []
Starter codePython
def quadratic_features(x):
# Your code here
pass4 test cases · run your code against them in the editor