Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- M = np.array([
- [15, 4, -1, 9, 10, 7],
- [-4, 2, 29, 11, 98, 5],
- [101, 24, 3, 19, 77, 53],
- [0, 88, 34, 62, 13, -9],
- [52, 93, 44, 46, 24, 125],
- [0, 17, 26, 8, 87, 0],
- [103, 19, 52, 173, 66, 24],
- [26, 78, 123, -5, 13, 41]
- ])
- num_rows = M.shape[0]
- num_colomns = M.shape[1]
- M_prime_0 = []
- for i in range(0, num_rows):
- M_row_sorted = np.sort(M[i])
- M_row_sorted_converted = []
- convert_value = 1
- for j in range(0, num_colomns - 1):
- if M_row_sorted[j] < M_row_sorted[j + 1]:
- M_row_sorted_converted.append((convert_value, M_row_sorted[j]))
- convert_value = convert_value + 1
- elif M_row_sorted[j] == M_row_sorted[j + 1]:
- M_row_sorted_converted.append((convert_value, M_row_sorted[j])
- M_row_sorted_converted.append((convert_value, M_row_sorted[num_colomns - 1]))
- new_row = [0] * num_colomns
- for k in M_row_sorted_converted:
- index_row = 0
- for k2 in M[i]:
- if k2 == k[1] :
- new_row[index_row] = k[0]
- index_row = index_row + 1
- M_prime_0.append(new_row)
- print("M1 = \n", M)
- print("\n=====================\n")
- M_prime = []
- for M_p_line in M_prime_0:
- M_prime.append(np.array(M_p_line))
- print("M_prime = \n", np.array(M_prime))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement