Changeset 2216 in lmdz_wrf
- Timestamp:
- Nov 6, 2018, 8:22:44 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2205 r2216 146 146 # multi_index_mat: Function to provide the multiple coordinates of a given value inside a matrix 147 147 # multi_index_string: Function to provide the indeces of every repetition of a group of characters within a string 148 # multi_index_vec: Function to provide the coordinates of multiples repetitions of a value inside a vector 148 149 # Nomasked: Function to bring back a given array wthout the masked values reducing a given dimension 149 150 # Nstr: Function to transform a number to string, but making sure it preserves … … 2385 2386 return valpos 2386 2387 2388 def multi_index_vec(vec,val): 2389 """ Function to provide the coordinates of multiples repetitions of a value 2390 inside a vector 2391 index_vec(vec,val) 2392 vec= vector with values 2393 val= value to search 2394 >>> vecv = np.arange(27) 2395 >>> vecv[2] = 22 2396 >>> vecv[12] = 22 2397 >>> multi_index_vec(vecv,22) 2398 2, 12, 22 2399 """ 2400 fname = 'multi_index_vec' 2401 2402 valpos = [] 2403 if type(vec) == type(np.arange(2)): 2404 for i in range(vec.shape[0]): 2405 if vec[i] == val: valpos.append(i) 2406 elif type(vec) == type(tuple([1,2])): 2407 for i in range(len(vec)): 2408 if vec[i] == val: valpos.append(i) 2409 elif type(vec) == type(range(2)): 2410 for i in vec: 2411 if vec[i] == val: valpos.append(i) 2412 else: 2413 print errormsg 2414 print ' ' + fname + ': type', type(vec), 'not ready !!' 2415 print ' available ones:', type(np.arange(2)), type(range(2)), \ 2416 type(tuple([1,2])) 2417 quit(-1) 2418 2419 if len(valpos) == 0: valpos.append(-1) 2420 2421 return valpos 2422 2387 2423 def index_mat(mat,val,quitval=True): 2388 2424 """ Function to provide the coordinates of a given value inside a matrix
Note: See TracChangeset
for help on using the changeset viewer.