I have the following code:
r = numpy.zeros(shape = (width, height, 9))
It creates a width x height x 9
matrix filled with zero
Yet another possibility not yet mentioned here is to use NumPy tile:
a = numpy.tile(numpy.nan, (3, 3))
Also gives
array([[ NaN, NaN, NaN],
[ NaN, NaN, NaN],
[ NaN, NaN, NaN]])
I don't know about speed comparison.
Another alternative is numpy.broadcast_to(val,n)
which returns in constant time regardless of the size and is also the most memory efficient (it returns a view of the repeated element). The caveat is that the returned value is read-only.
Below is a comparison of the performances of all the other methods that have been proposed using the same benchmark as in Nico Schlömer's answer.