python - Find ordered vector in numpy array -


i need find vector in numpy.array. example, have np.array named e , want find vector [1, 2] in e (meaning have index of vector inside matrix) apparently programm see vector when not present:

enter image description here

the code use built e in following:

import numpy np faces = np.array([[1,2,3,4],[5,6,2,1],[6,7,3,2],[7,8,4,3],[8,5,1,4],[8,7,6,5]]) e = np.zeros([6,4,2]) k in range(len(faces)):     = [faces[k][0], faces[k][1]]     b = [faces[k][1], faces[k][2]]      c = [faces[k][2], faces[k][3]]     d = [faces[k][3], faces[k][0]]     e[k] = np.array([a,b,c,d])  print('e: %s' %e) 

any clue how solve this?

try:

e[np.all((e-np.array([1,2]))==0, axis=2)] 

brief explanation. e-np.array([1,2]) returns [0,0] [1,2] in array e. np.all(..., axis=2 returns boolean array: true if [0,0] false otherwise (so things such [1,1] become false). finally, slice e.

to index of [1,2]'s (there may multiple sub vector [1,2]):

np.argwhere(np.all((e-array([1,2]))==0, axis=2)) 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -