I have a numpy array 'arr' of shape (100000,). I need to create a numpy matrix 'res_matrix' of shape 100000X100000 such that
for i in range(res_matrix.shape[0]):
for j in range(res_matrix.shape[1]):
res_matrix[i][j]= arr[i]*arr[j]
Sample input/output
arr=[1 2 4]
Output:
res_matrix:
[[1 2 4]
[2 4 18]
[4 8 16]]
Is there way to do vectorize this operation, to reduce the computation time of calculating 00000X100000 in loop?
np.multiply.outer(arr, arr)