Skip to content

Instantly share code, notes, and snippets.

@kocur4d
Created February 23, 2019 20:58
Show Gist options
  • Save kocur4d/849dd9ea005efcb929d68b5fd86bd74a to your computer and use it in GitHub Desktop.
Save kocur4d/849dd9ea005efcb929d68b5fd86bd74a to your computer and use it in GitHub Desktop.
Add column to np.array
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