如何在NetLogo中建立随机值矩阵? [英] How to make a matrix of random values in NetLogo?

查看:342
本文介绍了如何在NetLogo中建立随机值矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以轻松地在NetLogo中制作一个$ n \ cross m $矩阵?另外,是否可以用随机值填充此矩阵?谢谢.

Is there a way to easily make an $n \cross m$ matrix in NetLogo? Additionally would it be possible to fill this matrix with random values? Thanks.

推荐答案

此答案已针对NetLogo 6任务语法进行了更新

请参见 http://ccl.northwestern.edu/netlogo/docs/matrix. html 获取有关NetLogo矩阵扩展的文档.

See http://ccl.northwestern.edu/netlogo/docs/matrix.html for docs on NetLogo's matrix extension.

要创建矩阵,有几种基本方法可以做到:matrix:make-constantmatrix:make-identitymatrix:from-row-listmatrix:from-column-list.

For creating a matrix, there are several primitives that do that: matrix:make-constant, matrix:make-identity, matrix:from-row-list, matrix:from-column-list.

要创建矩阵并将其填充为随机值,建议您先定义此过程:

For creating a matrix and filling it with random values, I'd suggest defining this procedure first:

to-report fill-matrix [n m generator]
  report matrix:from-row-list n-values n [n-values m [runresult generator]]
end

然后由5到5的矩阵构成,例如由0到9范围内的随机整数组成,即:

Then to make, say, a 5 by 5 matrix, of, say, random integers in the range 0 to 9, it's:

fill-matrix 5 5 [-> random 10]

示例结果:

observer> show fill-matrix 5 5 [-> random 10]
observer: {{matrix:  [ [ 5 9 3 2 6 ][ 5 8 2 8 0 ][ 6 7 3 7 4 ][ 7 0 4 6 3 ][ 7 9 0 0 5 ] ]}}

这篇关于如何在NetLogo中建立随机值矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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