Numpy数组:根据条件存储坐标

时间:2017-06-30 13:52:25

标签: python arrays database numpy matplotlib

我试图根据条件在数据库中存储x,y,z点。这些条件来自NACL structure。例如,当x是偶数且y和z是奇数时,有一个NA原子 - 该坐标将被存储为NA原子。因此,当我搜索所有NA原子的位置时,我得到一个坐标列表。另一个线程询问similar question答案是基于使用np.where,但我不确定如何在此实现。

我的尝试在以下代码中:

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

#dimension/shape of grid and array
n = int (input("Enter CUBE dimension: "))

def cube(ax, n):
    #Creating Arrays
    parameter = np.arange(0,n,1)
    xx, yy, zz = np.meshgrid(parameter, parameter, parameter)
    valuesrange = np.zeros((n,n,n))
    #list of arrays
    a = [(xx,yy,zz)]
    # my attempt at the problem
    #    if xx % 2 == 0 and yy % 2 != 0 and zz % 2 !=0:
    #        NA = [(xx,yy,zz)]
    #   elif xx % 2 != 0 and yy % 2 != 0 and zz % 2 ==0:
    #       NA = [(xx,yy,zz)]
    #  Etc...

    print (a)
    scatterplot = ax.scatter(xx, yy, zz, c = valuesrange, cmap=plt.cm.spectral_r, vmin=0, vmax=1,edgecolor = 'black', alpha = .7)    
    return scatterplot


fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

scatterplot1 = cube(ax,n)
plt.colorbar(scatterplot1)
plt.show()

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

我认为将此添加到您的代码中将有助于澄清:

master feature

now i want to merge
| |
| | file needsToBeChangedForNewFeature.php was changed here again
| |
|/| i get a conflict for each change since this point
| |
| | file needsToBeChangedForNewFeature.php was changed here
| |
|/
|

我认为你缺少的是xx不是一个值,它是一个值矩阵。您需要将矩阵中每个位置的值相互比较。这是a link about iterating over NumPy Arrays