I am trying to parse through 2 vectors, and fill a matrix based on a formula. This is the way I am doing it, it is highly inefficient.
import numpy as np
list1 = [1, 2, 3, 4]
list2 = [20, 30, 40, 50, 60, 70, 80, 90]
array1 = np.array(list1)
array2 = np.array(list2)
columns = len(list1)
rows = len(list2)
matrix = np.zeros((rows, columns))
for column in range(0, columns):
for row in range(2*column, rows):
matrix[row, column] = round(10 * (array2[row] - array1[column]), 0)
print(matrix)
The output should be
[[190. 0. 0. 0.]
[290. 0. 0. 0.]
[390. 380. 0. 0.]
[490. 480. 0. 0.]
[590. 580. 570. 0.]
[690. 680. 670. 0.]
[790. 780. 770. 760.]
[890. 880. 870. 860.]]
This is an example, the real arrays are large. How can I use numpy built-in code to do this in the most efficient and optimized way?
Thank you