[Matrix-SIG] binarysearch? & Little more on combine 1D arrays
into 2D arrays?
David Ascher
da@skivs.ski.org
Thu, 8 Oct 1998 09:18:28 -0700 (Pacific Daylight Time)
On Thu, 8 Oct 1998, Yoon, Hoon (CICG - NY Program Trading) wrote:
> Just wanted to see I can extend this ? a bit more.
> Let's say I wanted to see
> a | d
>
> Is there a simpler way? (This isn't too bad, but I would like to skip
> a.shape = () step).
>
> a.shape = (1,3)
> concatenate((a,d),0)
> array([[0, 1, 2],
> [0, 1, 2],
> [3, 4, 5]])
The trick is to remember to use NewAxis:
>>> a
array([0, 1, 2])
>>> d
array([[0, 1, 2],
[3, 4, 5]])
>>> concatenate((a[NewAxis,:], d))
array([[0, 1, 2],
[0, 1, 2],
[3, 4, 5]])
Whenever you find yourself doing a reshape w/ a 1 somewhere, chances are
you can get away with a NewAxis operation instead, which is quicker and
simpler to read (IMO).
--david