Changeset 2298 in lmdz_wrf
- Timestamp:
- Jan 29, 2019, 7:54:10 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2279 r2298 171 171 # radius_dist: Function to generate a matrix with the distance at a given point 172 172 # rectangular_spiral: Function to provide a rectangular spiral (along x,y-axis values) of values 173 # remove_monotones: Function to remove the monotones (len(dim) = 1) from an array 173 174 # replace_list: Function to replace a value in a given list 174 175 # roman_to_int: Convert a roman numeral to an integer … … 15048 15049 return strlist 15049 15050 15051 def remove_monotones(array, dimns): 15052 """ Function to remove the monotones (len(dim) = 1) from an array 15053 array: array to remove the monotones 15054 dimns: list with the names of the dimensions of the array 15055 >>> remove_monotones(np.arange(20).reshape(4,1,5), ['dx', 'dy', 'dz']) 15056 (array([[ 0, 1, 2, 3, 4], 15057 [ 5, 6, 7, 8, 9], 15058 [10, 11, 12, 13, 14], 15059 [15, 16, 17, 18, 19]]), ['dx', 'dz']) 15060 """ 15061 fname = 'remove_monotones' 15062 15063 rank = len(array.shape) 15064 15065 newshape = [] 15066 newdims = [] 15067 slicev = [] 15068 for idd in range(rank): 15069 if array.shape[idd] == 1: slicev.append(0) 15070 else: 15071 newshape.append(array.shape[idd]) 15072 slicev.append(slice(0,array.shape[idd])) 15073 newdims.append(dimns[idd]) 15074 15075 newarray = np.zeros(tuple(newshape), dtype=array.dtype) 15076 newarray = array[tuple(slicev)] 15077 15078 return newarray, newdims 15079 15050 15080 #quit() 15051 15081
Note: See TracChangeset
for help on using the changeset viewer.