Veedrac is totally correct Veedrac is totally correct: you can't expect to compute a \$ 1000^2 \$ by \$ 1000^2 \$ array of distances: this would have \$ 10^{12} \$ elements, and if each element is a double-precision floating-point number then that would require 8 terabytes of memory.
Veedrac is totally correct: you can't expect to compute a \$ 1000^2 \$ by \$ 1000^2 \$ array of distances: this would have \$ 10^{12} \$ elements, and if each element is a double-precision floating-point number then that would require 8 terabytes of memory.
Veedrac is totally correct: you can't expect to compute a \$ 1000^2 \$ by \$ 1000^2 \$ array of distances: this would have \$ 10^{12} \$ elements, and if each element is a double-precision floating-point number then that would require 8 terabytes of memory.
As always when speeding up NumPy code As always when speeding up NumPy code, you should scrutinize every Python loop—that is, every for
, while
, generator and comprehension—to see if the computation can be vectorized, that is, transformed into a sequence of NumPy whole-array operations. The usual approach is to start by removing the innermost loops and work outwards.
As always when speeding up NumPy code, you should scrutinize every Python loop—that is, every for
, while
, generator and comprehension—to see if the computation can be vectorized, that is, transformed into a sequence of NumPy whole-array operations. The usual approach is to start by removing the innermost loops and work outwards.
As always when speeding up NumPy code, you should scrutinize every Python loop—that is, every for
, while
, generator and comprehension—to see if the computation can be vectorized, that is, transformed into a sequence of NumPy whole-array operations. The usual approach is to start by removing the innermost loops and work outwards.
Uarray = np.arange(U ** 2)
Ui = Uarray // U
, Uj = divmod(Uarray %, U)
which, using numpy.mgrid
,and this is the same as:
(see numpy.mgrid
).
Uarray = np.arange(U ** 2)
Ui = Uarray // U
Uj = Uarray % U
which, using numpy.mgrid
, is the same as: