您當前的位置:首頁 > 攝影

【Numpy】np.c_和np.r_的用法

作者:由 指尖聽戲 發表于 攝影時間:2022-07-26

numpy。c_() and numpy。r_()的用法

np.r_是按列連線兩個矩陣,就是把兩矩陣上下相加,要求列數相等。

np.c_是按行連線兩個矩陣,就是把兩矩陣左右相加,要求行數相等。

Demo:

1。numpy。c_:

import

numpy

as

np

x

=

np

arange

12

reshape

3

4

print

‘x:’

x

x

shape

y

=

np

arange

10

22

reshape

3

4

print

‘y:’

y

y

shape

z

=

np

c_

x

y

print

‘z:’

z

z

shape

result:

x

[[

0

1

2

3

4

5

6

7

8

9

10

11

]]

3

4

y

[[

10

11

12

13

14

15

16

17

18

19

20

21

]]

3

4

z

[[

0

1

2

3

10

11

12

13

4

5

6

7

14

15

16

17

8

9

10

11

18

19

20

21

]]

3

8

2。numpy。r_用法:

import

numpy

as

np

x

=

np

arange

12

reshape

3

4

print

‘x:’

x

x

shape

y

=

np

arange

10

22

reshape

3

4

print

‘y:’

y

y

shape

z

=

np

r_

x

y

print

‘z:’

z

z

shape

result:

x

[[

0

1

2

3

4

5

6

7

8

9

10

11

]]

3

4

y

[[

10

11

12

13

14

15

16

17

18

19

20

21

]]

3

4

z

[[

0

1

2

3

4

5

6

7

8

9

10

11

10

11

12

13

14

15

16

17

18

19

20

21

]]

6

4

標簽: np  print  shape  NumPy  arange