From 98e0ef3881ca2c13794c741618500ad9f0fd64cd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 28 Oct 2020 13:38:20 +0100 Subject: [PATCH] no loops taken from https://stackoverflow.com/questions/3403973 --- python/damask/_geom.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/damask/_geom.py b/python/damask/_geom.py index d5abe29a7..e0e6fcdc6 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -269,9 +269,10 @@ class Geom: if len(unique) == grid.prod(): ma = np.arange(grid.prod()) else: - ma = np.empty(grid.prod(),'i') - for to_ma,from_ma in enumerate(pd.unique(unique_inverse)): - ma[unique_inverse==from_ma] = to_ma + from_ma = pd.unique(unique_inverse) + sort_idx = np.argsort(from_ma) + idx = np.searchsorted(from_ma,unique_inverse,sorter = sort_idx) + ma = np.arange(from_ma.size)[sort_idx][idx] return Geom(ma.reshape(grid,order='F'),size,origin,util.execution_stamp('Geom','from_table'))