Hi, On Fri, Apr 20, 2012 at 9:15 PM, Andre Martel <soucoupevola...@yahoo.com>wrote:
> What would be the best way to remove the maximum from a cube and > "collapse" the remaining elements along the z-axis ? > For example, I want to reduce Cube to NewCube: > > >>> Cube > array([[[ 13, 2, 3, 42], > [ 5, 100, 7, 8], > [ 9, 1, 11, 12]], > > [[ 25, 4, 15, 1], > [ 17, 30, 9, 20], > [ 21, 2, 23, 24]], > > [[ 1, 2, 27, 28], > [ 29, 18, 31, 32], > [ -1, 3, 35, 4]]]) > > NewCube > > array([[[ 13, 2, 3, 1], > [ 5, 30, 7, 8], > [ 9, 1, 11, 12]], > > [[ 1, 2, 15, 28], > [ 17, 18, 9, 20], > [ -1, 2, 23, 4]]]) > > I tried with argmax() and then roll() and delete() but these > all work on 1-D arrays only. Thanks. > Perhaps it would be more straightforward to process via 2D-arrays, like: In []: C Out[]: array([[[ 13, 2, 3, 42], [ 5, 100, 7, 8], [ 9, 1, 11, 12]], [[ 25, 4, 15, 1], [ 17, 30, 9, 20], [ 21, 2, 23, 24]], [[ 1, 2, 27, 28], [ 29, 18, 31, 32], [ -1, 3, 35, 4]]]) In []: C_in= C.reshape(3, -1).copy() In []: ndx= C_in.argmax(0) In []: C_out= C_in[:2, :] In []: C_out[:, ndx== 0]= C_in[1:, ndx== 0] In []: C_out[1, ndx== 1]= C_in[2, ndx== 1] In []: C_out.reshape(2, 3, 4) Out[]: array([[[13, 2, 3, 1], [ 5, 30, 7, 8], [ 9, 1, 11, 12]], [[ 1, 2, 15, 28], [17, 18, 9, 20], [-1, 2, 23, 4]]]) My 2 cents, -eat > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > >
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion