Created
February 23, 2019 20:58
-
-
Save kocur4d/849dd9ea005efcb929d68b5fd86bd74a to your computer and use it in GitHub Desktop.
Add column to np.array
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
import numpy as np | |
X = np.array([ | |
[2.31, 4.58], | |
[1.56,4.27], | |
[5.48,5.61], | |
[0.03,1.49], | |
[6.13,6.07], | |
[2.36,4.75], | |
[2.14,4.3], | |
[2.01,4.37], | |
[2.11,4.43], | |
[4.57,4.87] | |
]) | |
mean_vector = X.mean(axis=1) | |
np.concatenate((X, mean_vector.reshape((-1,1))), axis=1) | |
# array([[2.31 , 4.58 , 3.445], | |
# [1.56 , 4.27 , 2.915], | |
# [5.48 , 5.61 , 5.545], | |
# [0.03 , 1.49 , 0.76 ], | |
# [6.13 , 6.07 , 6.1 ], | |
# [2.36 , 4.75 , 3.555], | |
# [2.14 , 4.3 , 3.22 ], | |
# [2.01 , 4.37 , 3.19 ], | |
# [2.11 , 4.43 , 3.27 ], | |
# [4.57 , 4.87 , 4.72 ]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment