[Numpy-discussion] reshape

Nadav Horesh nadavh at visionsense.com
Thu Nov 6 12:47:19 EST 2008


Can you clarify?

-----הודעה מקורית-----
מאת: numpy-discussion-bounces at scipy.org בשם Nils Wagner
נשלח: ה 06-נובמבר-08 17:13
אל: numpy-discussion at scipy.org
נושא: [Numpy-discussion] reshape
 
Hi all,

What can be done if
the new shape is not compatible with the original shape ?
The number of columns is fixed and should be 8.

One could split the original array C

>>> C
array([[  0.00000000e+00,   1.00000000e-01],
        [  4.15000000e+01,   1.00000000e-01],
        [  4.16000000e+01,   1.00000000e-01],
        [  6.07500000e+01,   1.00000000e-01],
        [  6.08500000e+01,   1.00000000e-01],
        [  8.22550000e+01,   1.00000000e-01],
        [  8.23550000e+01,   1.00000000e-01],
        [  9.42550000e+01,   1.00000000e-01],
        [  9.43550000e+01,   1.00000000e-01],
        [  9.99100000e+01,   1.00000000e-01],
        [  1.00010000e+02,   1.00000000e-01],
        [  1.07660000e+02,   1.00000000e-01],
        [  1.07760000e+02,   1.00000000e-01],
        [  1.28000000e+02,   1.00000000e-01],
        [  1.28100000e+02,   1.00000000e-01]])
>>> shape(C)
(15, 2)

>>> A = C[:8,:]
>>> A
array([[  0.   ,   0.1  ],
        [ 41.5  ,   0.1  ],
        [ 41.6  ,   0.1  ],
        [ 60.75 ,   0.1  ],
        [ 60.85 ,   0.1  ],
        [ 82.255,   0.1  ],
        [ 82.355,   0.1  ],
        [ 94.255,   0.1  ]])
>>> A = reshape(A,(2,8))
>>> A
array([[  0.   ,   0.1  ,  41.5  ,   0.1  ,  41.6  ,   0.1 
 ,  60.75 ,
           0.1  ],
        [ 60.85 ,   0.1  ,  82.255,   0.1  ,  82.355, 
  0.1  ,  94.255,
           0.1  ]])
>>> B = C[8:,:]
>>> B
array([[  9.43550000e+01,   1.00000000e-01],
        [  9.99100000e+01,   1.00000000e-01],
        [  1.00010000e+02,   1.00000000e-01],
        [  1.07660000e+02,   1.00000000e-01],
        [  1.07760000e+02,   1.00000000e-01],
        [  1.28000000e+02,   1.00000000e-01],
        [  1.28100000e+02,   1.00000000e-01]])
>>> B = reshape(B,(2,7))
>>> B
array([[  9.43550000e+01,   1.00000000e-01, 
  9.99100000e+01,
           1.00000000e-01,   1.00010000e+02, 
  1.00000000e-01,
           1.07660000e+02],
        [  1.00000000e-01,   1.07760000e+02, 
  1.00000000e-01,
           1.28000000e+02,   1.00000000e-01, 
  1.28100000e+02,
           1.00000000e-01]])

Nils
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 3191 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20081106/71f7c188/attachment.bin>


More information about the NumPy-Discussion mailing list