0

我试图在石墨烯的六角布里渊的 k 点周围选择一个三角形区域。我试过这样:

import random
import numpy as np

def trisample(A, B, C):
  r1 = float(random.random())
  r2 = float(random.random())
  s1 =float( np.sqrt(r1))
  x = float( A[0] * (1.0 - s1) + B[0] * (1.0 - r2) * s1 + C[0] * r2 * s1)
  y = float( A[1] * (1.0 - s1) + B[1] * (1.0 - r2) * s1 + C[1] * r2 * s1)
  return (x, y)
    
random.seed(5)
A = (0.2,0.1)
B = (0.5, 0.1)
C = (0.5, 0.0)
points = [trisample(A, B, C) for _ in range(10000)]

kxx, kyy = (zip(*points))

然后,我尝试kxx, kyy

(2*np.cos(2*np.pi*kyy) + 4*np.cos((3**0.5)*np.pi*kxx)*np.cos(np.pi*kyy))

但得到错误

TypeError                                 Traceback (most recent call last)

<ipython-input-5-cb758caa3c7d> in <module>()
----> 1 (2*np.cos(2*np.pi*kyy)+ 4*np.cos((3**0.5)*np.pi* kxx)*np.cos(np.pi*kyy))

TypeError: can't multiply sequence by non-int of type 'float'

我在做什么错误?如何摆脱这个错误?

4

1 回答 1

0

尝试将kxx和转换kyy为 numpy 数组:

kxx = np.array(kxx)
kyy = np.array(kyy)

在将它们插入该公式之前。

于 2018-03-26T07:45:52.020 回答