Advertisement
Guest User

Untitled

a guest
Oct 26th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import numpy as np
  2.  
  3. M = np.array([
  4. [15, 4, -1, 9, 10, 7],
  5. [-4, 2, 29, 11, 98, 5],
  6. [101, 24, 3, 19, 77, 53],
  7. [0, 88, 34, 62, 13, -9],
  8. [52, 93, 44, 46, 24, 125],
  9. [0, 17, 26, 8, 87, 0],
  10. [103, 19, 52, 173, 66, 24],
  11. [26, 78, 123, -5, 13, 41]
  12. ])
  13.  
  14. num_rows = M.shape[0]
  15. num_colomns = M.shape[1]
  16.  
  17. M_prime_0 = []
  18.  
  19. for i in range(0, num_rows):
  20.  
  21. M_row_sorted = np.sort(M[i])
  22. M_row_sorted_converted = []
  23.  
  24. convert_value = 1
  25.  
  26. for j in range(0, num_colomns - 1):
  27.  
  28. if M_row_sorted[j] < M_row_sorted[j + 1]:
  29.  
  30. M_row_sorted_converted.append((convert_value, M_row_sorted[j]))
  31.  
  32. convert_value = convert_value + 1
  33.  
  34. elif M_row_sorted[j] == M_row_sorted[j + 1]:
  35.  
  36. M_row_sorted_converted.append((convert_value, M_row_sorted[j])
  37.  
  38. M_row_sorted_converted.append((convert_value, M_row_sorted[num_colomns - 1]))
  39.  
  40. new_row = [0] * num_colomns
  41.  
  42. for k in M_row_sorted_converted:
  43.  
  44. index_row = 0
  45.  
  46. for k2 in M[i]:
  47.  
  48. if k2 == k[1] :
  49.  
  50. new_row[index_row] = k[0]
  51.  
  52. index_row = index_row + 1
  53.  
  54. M_prime_0.append(new_row)
  55.  
  56. print("M1 = \n", M)
  57.  
  58. print("\n=====================\n")
  59.  
  60. M_prime = []
  61.  
  62. for M_p_line in M_prime_0:
  63.  
  64. M_prime.append(np.array(M_p_line))
  65.  
  66. print("M_prime = \n", np.array(M_prime))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement