Expanding a vector by replicating elements individually
Robert Kern
robert.kern at gmail.com
Wed Sep 22 16:28:27 EDT 2010
On 9/21/10 10:03 PM, gburdell1 at gmail.com wrote:
> Given
>
> m=numpy.array([[1, 2, 3]])
>
> I want to obtain
>
> array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]])
>
> One way I've found to do this is:
>
> numpy.reshape(numpy.tile(m,(4,1)),(12,1),'f').T
>
> Another way is:
>
> numpy.reshape(numpy.tile(m,(4,1)).flatten(1),(1,12))
>
> Is there a simpler way to do this, without having to go jump through
> so many hoops?
Peter Otten gave you the correct answer. If you have more numpy questions, you
should ask on the numpy mailing list:
http://www.scipy.org/Mailing_Lists
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list