# numpy基础代码操练

+关注继续查看
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]: b
Out[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]: b
Out[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))
b.resize(2,12))
^
SyntaxError: invalid syntax

In [33]: b.resize((2,12))

In [34]: b
Out[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)
<ipython-input-35-0863ec9f918e> in <module>()
----> 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]: a
Out[37]:
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])

In [38]: b = 2 * a

In [39]: b
Out[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]: a
Out[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]: c
Out[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]: b
Out[54]:
array([[ 0,  2,  4],
[ 6,  8, 10],
[12, 14, 16]])

In [55]: b
Out[55]:
array([[ 0,  2,  4],
[ 6,  8, 10],
[12, 14, 16]])

In [56]: b.ndim
Out[56]: 2

In [57]: b.size
Out[57]: 9

In [58]: b.itemsize
Out[58]: 4

In [59]: b.nbytes
Out[59]: 36

In [60]: b.size * b.itemsize
Out[60]: 36

In [61]: b.resize(6,4)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-61-a30f6357ab78> in <module>()
----> 1 b.resize(6,4)

ValueError: cannot resize an array that references or is referenced
by another array in this way.  Use the resize function

In [62]: b.resize(6,6)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-62-5d4e603729e0> in <module>()
----> 1 b.resize(6,6)

ValueError: cannot resize an array that references or is referenced
by another array in this way.  Use the resize function

In [63]: b.resize()

In [64]: b
Out[64]:
array([[ 0,  2,  4],
[ 6,  8, 10],
[12, 14, 16]])

In [65]: b
Out[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]:

Spring Cloud Alibaba基础教程：支持的几种服务消费方式（RestTemplate、WebClient、Feign）

2592 0
Android JAVA 语言基础例子代码
Android的界面一般都是java开发的，因此对于c++，.net人员来说理解和编写有一个适应过程，最近参考了一下资料，把这些涉的一些java基础使用以例子代码的形式总结起来，记录了这个平台的熟悉过程。
857 0
Java基础-08总结帮助文档，代码块，继承
1:如何制作帮助文档(了解)(1)写一个类(2)加入文档注释(3)通过javadoc工具生成即可javadoc -d 目录 -author -version ArrayTool.java /*我想要对数组进行操作在同一个文件夹下，类定义在两个文件中和定义在一个文件中其实一样的。 */ class ArrayDemo {public static void main(String[]
1154 0
numpy基础代码操练
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]) ...
926 0
Python基础之:Python中的流程控制

166 0
《码出高效：Java 开发手册》正式发布，83行代码计划启动

11584 0

16617 0
+关注

1512

0

《2021云上架构与运维峰会演讲合集》

《零基础CSS入门教程》

《零基础HTML入门教程》