小编Ste*_*n F的帖子

Python 中的伊辛模型

我目前正在使用 Python3 为 Ising 模型编写代码。我对编码还很陌生。我有工作代码,但输出结果不符合预期,我似乎找不到错误。这是我的代码:

import numpy as np
import random


def init_spin_array(rows, cols):
    return np.random.choice((-1, 1), size=(rows, cols))


def find_neighbors(spin_array, lattice, x, y):
    left = (x , y - 1)
    right = (x, y + 1 if y + 1 < (lattice - 1) else 0)
    top = (x - 1, y)
    bottom = (x + 1 if x + 1 < (lattice - 1) else 0, y)

    return [spin_array[left[0], left[1]],
            spin_array[right[0], right[1]],
            spin_array[top[0], top[1]],
            spin_array[bottom[0], bottom[1]]]

def energy(spin_array, …
Run Code Online (Sandbox Code Playgroud)

python physics montecarlo python-3.x

3
推荐指数
1
解决办法
9321
查看次数

标签 统计

montecarlo ×1

physics ×1

python ×1

python-3.x ×1