gpt4 book ai didi

python - Numpy如何遍历数组的列?

转载 作者:IT老高 更新时间:2023-10-28 21:11:29 35 4
gpt4 key购买 nike

假设我有 m x n 数组。我想将此数组的每一列传递给一个函数以对整个列执行一些操作。如何遍历数组的列?

例如,我有一个 4 x 3 数组

1  99 2
2 14 5
3 12 7
4 43 1

for column in array:
some_function(column)

其中列在第一次迭代中为“1,2,3,4”,第二次为“99,14,12,43”,第三次为“2,5,7,1”。

最佳答案

只需遍历数组的转置:

for column in array.T:
some_function(column)

关于python - Numpy如何遍历数组的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10148818/

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