Skip to content
Advertisement

Fastest way to create a square nxn matrix from 1d array in numpy

Suppose the following numpy array:

JavaScript

I want to know the fastest way to generate the following operation:

JavaScript

(1) How to efficiently create matrix “result” (because n >> 0 can be very large) ?

(2) Does this matrix have a particular name ?

Advertisement

Answer

This is a bit faster:

JavaScript

cursory benchmarks, nothing scientific. (timeit 100 times with arr):

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement