I have generated a 4 by 4 array. Then I generating a 1D array of 1s and 0s of length 8 such as [0 1 0 1 0 1 1 0]. I then generated a seed that will be used to create a sample of random indices. The number of indices generated are equal to the number of elements in the message. I now wish to add the elements of the message in the indices generated which represent the locations of the indices in the 4 by 4 array. After adding the elements of the message in the indices of the 4 by 4 matrix. I wish to display the new 4 by 4 array matrix with the added elements.
import numpy as np
import random
from PIL import Image
import matplotlib.pyplot as plt
#array
cover = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
max_len = (4 * 4) #since we have a 4 by 4 array
#Generating Message
msg = np.random.randint(2, size=8)
len_msg = len(msg)
#Generating a seed which will be used to locate where the msg will be added in the matrix
seed = 4
print "The chosen seed is %d" % (seed)
random.seed(seed)
#Generate Indices to be used to add in matrix
indices = random.sample(range(len_msg, max_len),len_msg)
Aucun commentaire:
Enregistrer un commentaire