Skip to content

Instantly share code, notes, and snippets.

@wiccy46
Created July 19, 2019 09:44
Show Gist options
  • Select an option

  • Save wiccy46/62a8fc7f5e25fea172f716e7c3ab0d72 to your computer and use it in GitHub Desktop.

Select an option

Save wiccy46/62a8fc7f5e25fea172f716e7c3ab0d72 to your computer and use it in GitHub Desktop.
[numpy_subset]A collection of different number subsetting #python
"""To get a new array by subsetting columns of different np.ndarray"""
a = np.array([[1,2],[3,4],[5,6]])
b = np.array([[10,20],[30,40],[50,60]])
# Using zip
[(a_s[0], b_s[0]) for a_s, b_s in zip(a,b)]
# A faster way is to concat and ravel, use ('float, float') if float number.
np.c_[a[:,0],b[:,0]].view('i,i').ravel()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment