- Timestamp:
- Apr 13, 2018, 3:12:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r1902 r1903 115 115 # multi_index_string: Function to provide the indeces of every repetition of a group of characters within a string 116 116 # Nomasked: Function to bring back a given array wthout the masked values reducing a given dimension 117 # Nstr: Function to transform a number to string, but making sure it preserves 118 # characteristics of the number 117 119 # Ntchar: Function to repeat a number of times a given tring 118 120 # num_chainSnum: Function to pass a value to a `ChainStrNum' number … … 13042 13044 return newmatdate 13043 13045 #print advance_matDate([1976, 02, 27, 23, 59, 0], [0, 11, 0, 0, 2, 0]) 13046 13047 def Nstr(number): 13048 """ Function to transform a number to string, but making sure it preserves 13049 characteristics of the number 13050 >>> Nstr(np.float(1./3.)) 13051 0.33333333 13052 >>> Nstr(np.float32(1./3.)) 13053 0.33333334 13054 >>> Nstr(np.float64(1./3.)) 13055 0.3333333333333333 13056 """ 13057 fname = 'Nstr' 13058 13059 if type(number) == type(1) or type(number) == type(long)): 13060 newStr = '{:d}'.format(number) 13061 elif type(number) == type(np.int16(1)) type(number) == type(np.int32(1)) or \ 13062 type(number) == type(np.int64(1)): 13063 newStr = '{:d}'.format(number) 13064 elif type(number) == type(float(1.)) or type(number) == type(np.float(1.)): 13065 newStr = '{:.8f}'.format(number) 13066 elif type(number) == type(np.float32(1.)): 13067 newStr = '{:.8f}'.format(number) 13068 elif type(number) == type(np.float64(1.)): 13069 newStr = '{:.16f}'.format(number) 13070 13071 return newStr 13072 13073 print Nstr(np.float(1./3.)) 13074 13075 print Nstr(np.float32(1./3.)) 13076 13077 print Nstr(np.float64(1./3.)) 13078 13044 13079 #quit() 13045 13080
Note: See TracChangeset
for help on using the changeset viewer.