如何在APL中定义普适函数?
我做的是
function?{
(??(????)){the function that apply to scalar}¨?
}
Run Code Online (Sandbox Code Playgroud)
我认为应该有一个更好的方法,我没有看到它.
APL 中的大多数原始函数已经很普遍。因此,除非您做一些奇特的事情,否则您的自定义函数已经很普遍了。例如
\n\nf\xe2\x86\x90{\xc3\xb71+*-\xe2\x8d\xb5} \xe2\x8d\x9d sigmoid, f(x)=1/(1+exp(-x))\nRun Code Online (Sandbox Code Playgroud)\n\n将适用于数组和标量。
\n\n如果你确实做了一些奇特的事情并且你有一个非普遍功能f,你可以通过以下方式将其变成\n普遍功能:
g\xe2\x86\x90{0=\xe2\x8d\xb4\xe2\x8d\xb4\xe2\x8d\xb5:f\xe2\x8d\xb5 \xe2\x8b\x84 \xe2\x88\x87\xc2\xa8\xe2\x8d\xb5} \xe2\x8d\x9d the pervasive version of f\nRun Code Online (Sandbox Code Playgroud)\n\n可以理解为:如果参数是标量,则f对其应用,否则递归地进入参数的每一项。