首页
软件开发
登录
6mi
u
盘
搜
搜 索
软件开发
numpy的newaxis
numpy的newaxis
xiaoxiao
2022-07-03
141
newaxis的作用为给numpy数组增加新的维度 示例代码:
import
numpy
as
np a
=
np
.
array
(
[
1
,
2
,
3
]
)
#a.shsape=(3,)
a1
=
a
[
np
.
newaxis
,
:
]
#a1.shape=(1,3)
print
(
a1
)
#[[1 2 3]]
a2
=
a
[
:
,
np
.
newaxis
]
#a2.shape=(3,1)
print
(
a2
)
打印结果:
[
[
1
2
3
]
]
[
[
1
]
[
2
]
[
3
]
]
总结:np.newaxis放在哪个维度上,那个维度就增加1
转载请注明原文地址: https://yun.8miu.com/read-20340.html
最新回复
(
0
)