我可以使用带有固定输入的`map`吗? [英] Can I use `map` with fixed input?
本文介绍了我可以使用带有固定输入的`map`吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我这样做 f(x,y) = 2x + y
然后 map(f, [2,4,6],[1,1,1])
我会得到:
Suppose I do f(x,y) = 2x + y
then 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:
广播(f, [2,4,6],1)
输出:
Int64[3]
5
9
13
这篇关于我可以使用带有固定输入的`map`吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文