我在matlab中编写了如下代码:
T= ((1-(-1)) * rand([4,4],'double') + (-1) * ones(4,4));
for i=1:4
for j=1:i
T(j,i)=TT(i,j);
end
T(i,i)=0;
end
现在,我想按以下方式在mathematica中编写此代码:
T = RandomReal[{-1, 1}, {4, 4}];
For[i = 1, i < 5, i++,
For[ j = 1, j < i, j++,
T[[j, i]] = T[[i, j]]]
T[[i, i]] = 0];
但这不起作用! 你能告诉我我的错误吗? 谢谢。
答案 0 :(得分:0)
const {flow, get, curry} = require('lodash');
const people = [
{name: 'jenny', friends: ['jeff']},
{name: 'frank', friends: ['jeff', 'ross']},
{name: 'sarah', friends: []},
{name: 'jeff', friends: ['jenny', 'frank']},
{name: 'russ', friends: []},
{name: 'calvin', friends: []},
{name: 'ross', friends: ['frank']},
];
const not = i => !i;
const withFriends = i => flow(
Boolean,
get(i, 'friends.length'), // arity of this is 2 so might be harder to lift, is it possible tho with curry?
); // No idea what i'm doing here.
const peopleWithFriends = people.filter(withFriends);
console.log(peopleWithFriends);
const withoutFriends = flow(not, withFriends);
const peopleWithoutFriends = people.filter(withoutFriends);
console.log(peopleWithoutFriends);
如果必须使用SeedRandom[1234];
t = u = RandomReal[{-1, 1}, {4, 4}];
t // MatrixForm
For
它会突变For[i = 1, i < 5, i++,
For[j = 1, j < i, j++, t[[j, i]] = t[[i, j]]]; t[[i, i]] = 0];
t
一种功能上实现此目的的方法
t // MatrixForm