def compact(vertices, indices, tolerance=0.001):
 n = len(vertices)
 V = np.zeros(n, dtype=[('pos', np.float32, 3)])
 V['pos'][:, 0] = vertices[:, 0]
 V['pos'][:, 1] = vertices[:, 1]
 V['pos'][:, 2] = vertices[:, 2]
 epsilon = 0.001
 decimals = int((np.log(epsilon) / np.log((1 / 10.0))))
 V_ = np.zeros_like(V)
 X = V['pos'][:, 0].round(decimals=decimals)
 X[np.where((abs(X) < epsilon))] = 0
 V_['pos'][:, 0] = X
 Y = V['pos'][:, 1].round(decimals=decimals)
 Y[np.where((abs(Y) < epsilon))] = 0
 V_['pos'][:, 1] = Y
 Z = V['pos'][:, 2].round(decimals=decimals)
 Z[np.where((abs(Z) < epsilon))] = 0
 V_['pos'][:, 2] = Z
 (U, RI) = np.unique(V_, return_inverse=True)
 indices = indices.ravel()
 I_ = indices.copy().ravel()
 for i in range(len(indices)):
  I_[i] = RI[indices[i]]
 I_ = I_.reshape((len(indices) / 3), 3)
 return (U.view(np.float32).reshape(len(U), 3), I_, RI)

def compact ( vertices , indices , tolerance = 0.001 ) : n = len ( vertices ) V = np . zeros ( n , dtype = [ ( 'pos' , np . float32 , 3 ) ] ) V [ 'pos' ] [ : , 0 ] = vertices [ : , 0 ] V [ 'pos' ] [ : , 1 ] = vertices [ : , 1 ] V [ 'pos' ] [ : , 2 ] = vertices [ : , 2 ] epsilon = 0.001 decimals = int ( ( np . log ( epsilon ) / np . log ( ( 1 / 10.0 ) ) ) ) V_ = np . zeros_like ( V ) X = V [ 'pos' ] [ : , 0 ] . round ( decimals = decimals ) X [ np . where ( ( abs ( X ) < epsilon ) ) ] = 0 V_ [ 'pos' ] [ : , 0 ] = X Y = V [ 'pos' ] [ : , 1 ] . round ( decimals = decimals ) Y [ np . where ( ( abs ( Y ) < epsilon ) ) ] = 0 V_ [ 'pos' ] [ : , 1 ] = Y Z = V [ 'pos' ] [ : , 2 ] . round ( decimals = decimals ) Z [ np . where ( ( abs ( Z ) < epsilon ) ) ] = 0 V_ [ 'pos' ] [ : , 2 ] = Z ( U , RI ) = np . unique ( V_ , return_inverse = True ) indices = indices . ravel ( ) I_ = indices . copy ( ) . ravel ( ) for i in range ( len ( indices ) ) : I_ [ i ] = RI [ indices [ i ] ] I_ = I_ . reshape ( ( len ( indices ) / 3 ) , 3 ) return ( U . view ( np . float32 ) . reshape ( len ( U ) , 3 ) , I_ , RI )
compact iterable by removing falsy values .