Created
March 14, 2022 15:54
-
-
Save rickhg12hs/3ae86f4e8b4a9af9b0335c6bf6ff8120 to your computer and use it in GitHub Desktop.
`PolynomialFeatures(2)` with out `sklearn`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new_M = np.apply_along_axis(lambda x: np.array([x[k1]*x[k2] for k2 in range(len(x)) for k1 in range(len(x)) if k1>=k2]), axis=1, arr=M) | |
N.B.: ^ could be simpler and more efficient | |
Is _roughly_ equivalent to: | |
[pseudocode] | |
new_M = empty array | |
Foreach row in M: | |
row_length = len(row) | |
new_row = empty row | |
for k1 in range(row_length): | |
for k2 in range(k1, row_length); | |
append row[k1]*row[k2] to new_row | |
append new_row to new_M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment