> 其他 >
Mathematica的一道很简单的函数应用题,
See the following statement.What does it do?Create a function that takes as input the matrix mat,and then for each element compares it with value \[Tau],and if a value is below \[Tau],it should be set to zero,else to 1.
mat = RandomInteger[100,RandomInteger[{15,25},2]]
我自己写的是
Resetlist[l_,x_] :=
For[i = 1,i
人气:148 ℃ 时间:2020-05-19 00:44:20
解答
行才有鬼啊,看看mat是几维的列表,还有根本没必要用啰嗦又麻烦的For:Clear[f]f[\[Tau]_, m_] := Map[UnitStep[# - \[Tau]] &, m, {2}]f[5, mat]...啊啊啊?求解释和解决方案呀大神

解决方案不是已经写在上面了吗……就这三行代码。顺便提供一个更快但是更需要对Mathematica有理解的解法:

ClearAll[f]
SetAttributes[f, Listable]
f[\[Tau]_, m_] := UnitStep[m - \[Tau]]
f[5, mat]
哇,真的可以,但是我不太理解,unitstep 和 map 的含义啊,按下F1,查自带帮助去。自带帮助已经说的很详细了。好吧,其实我的那个mathematica不知道为什么f1 从来搜索不到函数。八成是安装有问题。一个变通方法是,使用在线版的Mathematica帮助。你在网上搜一下Mathematica Documentation就可以找到了。
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版