计算满足特定条件的数组中的点

时间:2017-07-13 19:07:35

标签: arrays python-3.x numpy

我无法让我的代码计算来自三个不同数组的正确数量的元素,每个数组都有自己的参数。如果它满足所有三个参数,我想要计算元素,这是我到目前为止的

import numpy as np
import random as rand
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')

n = 10
x0 = np.zeros(n)
y0 = np.zeros(n)
z0 = np.zeros(n)

x1 = np.zeros(n)
y1 = np.zeros(n)
z1 = np.zeros(n)


hit = 0
for k in range (n):
theta = rand.uniform(0.0, np.pi)
phi = rand.uniform(0, (2 * np.pi)) 
x0[k] = np.sin(phi) * np.cos(theta)
y0[k] = np.sin(phi) * np.sin(theta)
z0[k] = np.cos(theta)

for j in range (n):
    theta = rand.uniform(0.0, np.pi)
    phi = rand.uniform(0, (2 * np.pi))
    x1[j] = np.sin(phi) * np.cos(theta)
    y1[j] = np.sin(phi) * np.sin(theta)
    z1[j] = np.cos(theta)

    for i in range(n):
        if np.any(x1[j] > -0.3) and np.any(x1[j] < 0.7) and  np.any(y1[j] > -0.3) and  np.any(y1[j] <0.7) and np.any(z1[j] > -0.3) and np.any(z1[j] < 0.3):
            hit += 1
ax.plot_wireframe([x0[k],x1[j]],[y0[k],y1[j]],[z0[k],z1[j]])


print (hit)
print (x1,y1,z1)

plt.show()

如果他们满足这三个参数,我想只计算终点。

谢谢

0 个答案:

没有答案