我遇到了一個看似簡單的問題。我有一個X,Y,Z格式的原子座標列表。我已經使用numpy.linspace()從Z座標列出'bin'列表。 Z座標是這樣的,它們排序後的點之間的差異可能只是小數或整數。我想移過'bin',只添加落入'bin0' - 'bin1'和'bin1-bin2'範圍的座標集的X,Y,Z。基本上這是我想要做的一些非常糟糕的僞代碼。我已經有了,我想爲「本」使用均勻間隔的號碼範圍對數據集使用範圍
1. Find XYZ coordinate sets that fall into first 'bin'
2. Do math on them and save the value out
3. Move on to next bin.
我知道有可能是一個簡單的蟒蛇解決方案,但在範圍內的工作我的列表內涵的理解是有限的。任何提示都非常感謝。
編輯* 嘗試如果您的數據是一個元組列表中增加了「SSCCE」
import numpy as np
xyz = [[2,-2,0.29],[ -2,0,1.9 ],[2,1,2.35],[2,-3,2.96],[ 2,0,4.97],[0,3,5.13],[-1,3,5.41]]
bins = [0,0.57,1.14,1.71,2.28,2.85555556, 3.42, 3.99, 4.56,5.14]
'''Now I want to add all of the xyz's with a z-value between 0 and .57 a list or somthing so that I can use them,
then I want to move on to the xyz's that fall between .57 and 1.14'''
workingXYZs = []
for x,y,z in xyz:
for i in bins:
if z > i: #but not greater than next I
#do math and move on to next interval
你能給我們一個簡短的,自包含的,正確的代碼和數據的例子嗎?這是很不清楚你要求什麼。 http://sscce.org/ – Wilduck 2013-03-25 22:02:33
使用列表理解從整個列表中分離出有用的數據比使用for for循環更快。 – 2013-03-25 23:51:43