rougier / from-python-to-numpy

An open-access book on numpy vectorization techniques, Nicolas P. Rougier, 2017
http://www.labri.fr/perso/nrougier/from-python-to-numpy
Other
2.06k stars 340 forks source link

neighbours array in game of life example (Uniform Vectorization) #98

Open aaarbk opened 3 years ago

aaarbk commented 3 years ago

In the compute_neighbours() function, I think you meant to do N = [[0,]*(shape[1]) for i in range(shape[0])] instead of N = [[0,]*(shape[0]) for i in range(shape[1])]

rougier commented 3 years ago

Thansk. Did you try with non-equal size arrays to check if it is actually wrong? (I don't remember the exact layout I used)

aaarbk commented 3 years ago

Yes I did.

You defined the shape of Z as

shape = len(Z), len(Z[0])

so you want N to be [[0] * ncols for _ in range(nrows)] where (nrows, ncols) = shape

rougier commented 3 years ago

I see, thanks. Can you make a PR?