可以使用固定输入的`map`吗? [英] Can I use `map` with fixed input?

查看:65
本文介绍了可以使用固定输入的`map`吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我先f(x,y) = 2x + y然后map(f, [2,4,6],[1,1,1]) 我会得到:

Suppose I do f(x,y) = 2x + ythen map(f, [2,4,6],[1,1,1]) I will get:

3-element Array{Int64,1}:
  5
  9
 13


如果我执行map(f, [2,4,6],1),即我想假设第二个输入始终相同, 我会得到:


If I do map(f, [2,4,6],1), i.e., I want to suppose that the second input is always the same, I will get:

1-element Array{Any,1}:
5

所以这不起作用.有没有一种方法,而无需对Vector [1,1,1]进行编码?

So this does not work. Is there a way to do this without coding a Vector [1,1,1] ?

推荐答案

广播行为类似",它将数组更改为可以正常工作的大小并映射:

Broadcast "acts like" it changes the arrays to be a size which works, and maps:

broadcast(f, [2,4,6],1)

输出:

Int64[3]
5
9
13

这篇关于可以使用固定输入的`map`吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆