[Numpy-discussion] make hstack and vstack promote 1-D argument to 2-D when necessary

Robert Kern robert.kern@gmail....
Mon Nov 23 18:51:21 CST 2009

On Mon, Nov 23, 2009 at 18:43, Dr. Phillip M. Feldman
<pfeldman@verizon.net> wrote:
> I opened ticket #1302 to make the following enhancement request:
> I'd like to see hstack and vstack promote 1-D arguments to 2-D when this is
> necessary to make the dimensions match.  In the following example, c_ works
> as expected while hstack does not:

This isn't going to change. It would be inconsistent with the way we
promote 1D arrays to higher dimensions when broadcasting (i.e. we
always prepend 1s to the shape tuple so 1D arrays are treated like 2D
row vectors).

For the hstack() case, you might want to use column_stack() which
explicitly treats 1D arrays like columns. Otherwise, just use column
vectors explicitly.

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 NumPy-Discussion mailing list