pikaliov

2d_array_sort

Mar 19th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import numpy as np
  2. from copy import deepcopy
  3.  
  4. def func():
  5.     filename = 'test.txt'
  6.     strok1 = '8 7 9 5 90'
  7.     strok2 = '2 4 5 7 9 0'
  8.     with open(filename, 'w') as of:
  9.         of.write('{}\n{}\n'.format(strok1, strok2))
  10.  
  11.     t_array = np.empty(0)
  12.     with open(filename, 'r') as i_f:
  13.         for line in i_f:
  14.             t = line.split('\n')
  15.             if len(t) > 0 and len(t[0]) > 0:
  16.                 t_array = np.append(t_array, np.asarray(t[0].split(' '), np.int))
  17.     t_array[::-1].sort()
  18.     array_desc = deepcopy(t_array)
  19.     t_array.sort()
  20.     array_asc = deepcopy(t_array)
  21.     print('Array in desc order: -->\n{}\nArray in asc order: -->\n{}\n'.format(array_desc, array_asc))
  22.  
  23. if __name__ == "__main__":
  24.     func()
Advertisement
Add Comment
Please, Sign In to add comment