Spaces:
Running
Running
File size: 546 Bytes
c52280c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import numpy as np
def generate_matrix_from_index(A, len=25):
matrix = np.zeros(len, dtype=float)
matrix[A] = 1
return matrix
def retrieve_index_from_matrix(matrix):
A = np.where(matrix == 1)[0]
return A
if __name__ == '__main__':
# Generating a matrix from index A
A = 6
matrix = generate_matrix_from_index(A)
print("Generated Matrix:")
print(matrix)
# Retrieving index A from the matrix
retrieved_A = retrieve_index_from_matrix(matrix)
print("Retrieved Index A:")
print(retrieved_A)
|