Python 与 R : apply a function to each element in a vector

标签 python apply

我想对向量中的每个元素应用一个函数 (len)。在 R 中,我可以使用 sapply(cities,char) 轻松做到这一点。在不编写循环的情况下,Python 中是否有这样的替代方案?

最佳答案

语法是map(function, list)

例子:

map(len, [ [ 1,2,3], [4,5,6] ])

输出:

[ 3, 3 ]

关于Python 与 R : apply a function to each element in a vector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41170762/

相关文章:

python - Python 中的多元线性回归?

javascript - Crockford "new"方法

r - 使用 apply 在缺少值和字符串的数据框中查找最大值

python - 删除字典中的键/值对不起作用

python - 遍历 numpy 数组的最快方法是什么

r - 按行获取 x 值之间的平均列数

javascript - $.when.apply 返回结果集?

python - 用 pandas 中训练数据的平均值填充测试数据中的 nan 值

python - SAT 最小翻译向量不正确

python - wxpython 仪表没有脉冲