Consider the following (Nx1) array:
a = [[1]
[2]
[3]
[4]
[5]]
How to generate an (NxN) array from a? For e.g. N = 5:
a = [[1 1 1 1 1]
[2 2 2 2 2]
[3 3 3 3 3]
[4 4 4 4 4]
[5 5 5 5 5]]
If you want to copy the values, you can use np.repeat:
>>> np.repeat(a, len(a), 1)
array([[1, 1, 1, 1, 1],
[2, 2, 2, 2, 2],
[3, 3, 3, 3, 3],
[4, 4, 4, 4, 4],
[5, 5, 5, 5, 5]])
Else, you should perform a broadcast and wrap a with a view using np.broadcast_to:
>>> np.broadcast_to(a, (len(a),)*2)
array([[1, 1, 1, 1, 1],
[2, 2, 2, 2, 2],
[3, 3, 3, 3, 3],
[4, 4, 4, 4, 4],
[5, 5, 5, 5, 5]])
A pythonic one liner to generate the two dimensional array
a = [[1], [2], [3], [4], [5]]
N = 5
x = [i * N for i in a]
Sources: