gpt4 book ai didi

python - numpy.repeat 的反义词是什么?

转载 作者:太空宇宙 更新时间:2023-11-04 08:45:55 27 4
gpt4 key购买 nike

给出的答案here解释如何从

调整数组大小
[1,5,9]
[2,7,3]
[8,4,6]

[1,1,5,5,9,9]
[1,1,5,5,9,9]
[2,2,7,7,3,3]
[2,2,7,7,3,3]
[8,8,4,4,6,6]
[8,8,4,4,6,6]

使用 np.repeat。给定下层数组,将其缩小到上层的最佳方法是什么?

最佳答案

Slice以适当的步长跨越两个轴 -

a[::2,::2] # 2 being stepsize here

sample 运行-

In [23]: a
Out[23]:
array([[1, 1, 5, 5, 9, 9],
[1, 1, 5, 5, 9, 9],
[2, 2, 7, 7, 3, 3],
[2, 2, 7, 7, 3, 3],
[8, 8, 4, 4, 6, 6],
[8, 8, 4, 4, 6, 6]])

In [24]: a[::2,::2]
Out[24]:
array([[1, 5, 9],
[2, 7, 3],
[8, 4, 6]])

关于python - numpy.repeat 的反义词是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40617710/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com