本文共 5325 字,大约阅读时间需要 17 分钟。
In [20]: b[0,:,1]Out[20]: array([1, 5, 9])In [21]: b[0,:,1]Out[21]: array([1, 5, 9])In [22]: b[0,:,-1]Out[22]: array([ 3, 7, 11])In [23]: b[0,::-1, -1]Out[23]: array([11, 7, 3])In [24]: b[0,::-2, -1]Out[24]: array([11, 3])In [25]: b[::-1]Out[25]:array([[[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]], [[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]])In [26]: bOut[26]:array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]], [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]])In [27]: b.ravel()Out[27]:array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23])In [28]: b.flatten()Out[28]:array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23])In [29]: b.shape = (6,4)In [30]: bOut[30]:array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]])In [31]: b.transpose()Out[31]:array([[ 0, 4, 8, 12, 16, 20], [ 1, 5, 9, 13, 17, 21], [ 2, 6, 10, 14, 18, 22], [ 3, 7, 11, 15, 19, 23]])In [32]: b.resize(2,12)) File "", line 1 b.resize(2,12)) ^SyntaxError: invalid syntaxIn [33]: b.resize((2,12))In [34]: bOut[34]:array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]])In [35]: a = arange(3).reshape(3,3)---------------------------------------------------------------------------ValueError Traceback (most recent call last) in ()----> 1 a = arange(3).reshape(3,3)ValueError: cannot reshape array of size 3 into shape (3,3)In [36]: a = arange(9).reshape(3,3)In [37]: aOut[37]:array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])In [38]: b = 2 * aIn [39]: bOut[39]:array([[ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]])In [40]: hstack((a,b))Out[40]:array([[ 0, 1, 2, 0, 2, 4], [ 3, 4, 5, 6, 8, 10], [ 6, 7, 8, 12, 14, 16]])In [41]: concatenate((a,b), axis=1)Out[41]:array([[ 0, 1, 2, 0, 2, 4], [ 3, 4, 5, 6, 8, 10], [ 6, 7, 8, 12, 14, 16]])In [42]: vstack((a,b))Out[42]:array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]])In [43]: concatenate((a,b), axis=0)Out[43]:array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]])In [44]: dstack((a,b))Out[44]:array([[[ 0, 0], [ 1, 2], [ 2, 4]], [[ 3, 6], [ 4, 8], [ 5, 10]], [[ 6, 12], [ 7, 14], [ 8, 16]]])In [45]: aOut[45]:array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])In [46]: hsplit(a, 3)Out[46]:[array([[0], [3], [6]]), array([[1], [4], [7]]), array([[2], [5], [8]])]In [47]: hsplit(a, 3)Out[47]:[array([[0], [3], [6]]), array([[1], [4], [7]]), array([[2], [5], [8]])]In [48]: split(a, 3, axis=1)Out[48]:[array([[0], [3], [6]]), array([[1], [4], [7]]), array([[2], [5], [8]])]In [49]: vsplit(a, 3)Out[49]: [array([[0, 1, 2]]), array([[3, 4, 5]]), array([[6, 7, 8]])]In [50]: split(a, 3, axis=0)Out[50]: [array([[0, 1, 2]]), array([[3, 4, 5]]), array([[6, 7, 8]])]In [51]: c = arange(27).reshape(3, 3, 3)In [52]: cOut[52]:array([[[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8]], [[ 9, 10, 11], [12, 13, 14], [15, 16, 17]], [[18, 19, 20], [21, 22, 23], [24, 25, 26]]])In [53]: dsplit(c,3)Out[53]:[array([[[ 0], [ 3], [ 6]], [[ 9], [12], [15]], [[18], [21], [24]]]), array([[[ 1], [ 4], [ 7]], [[10], [13], [16]], [[19], [22], [25]]]), array([[[ 2], [ 5], [ 8]], [[11], [14], [17]], [[20], [23], [26]]])]In [54]: bOut[54]:array([[ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]])In [55]: bOut[55]:array([[ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]])In [56]: b.ndimOut[56]: 2In [57]: b.sizeOut[57]: 9In [58]: b.itemsizeOut[58]: 4In [59]: b.nbytesOut[59]: 36In [60]: b.size * b.itemsizeOut[60]: 36In [61]: b.resize(6,4)---------------------------------------------------------------------------ValueError Traceback (most recent call last) in ()----> 1 b.resize(6,4)ValueError: cannot resize an array that references or is referencedby another array in this way. Use the resize functionIn [62]: b.resize(6,6)---------------------------------------------------------------------------ValueError Traceback (most recent call last) in ()----> 1 b.resize(6,6)ValueError: cannot resize an array that references or is referencedby another array in this way. Use the resize functionIn [63]: b.resize()In [64]: bOut[64]:array([[ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]])In [65]: bOut[65]:array([[ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]])In [66]: b.tolist()Out[66]: [[0, 2, 4], [6, 8, 10], [12, 14, 16]]In [67]:
转载地址:http://yvcia.baihongyu.com/