2011-08-17 3 views
-1

저는 임의의 크기 (NxMxZ)의 3D 행렬, 총 50MB의 부동 소수점을 처리하려고합니다. 축과 대각선에서 가능한 단순하고 효율적인 합계 및 평균 계산을 할 필요가 있지만 그다지 공상적인 매트릭스는 없습니다.순수 Python NxMxZ 행렬 라이브러리를 찾고 있습니다.

누구든지 이러한 라이브러리가 있는지 알고 있습니까? 파이썬 용 "3D 매트릭스"라이브러리를 많이 찾았습니다.하지만 3D 그래픽 용이며 3D 그래픽 전용입니다. 4x4x4 행렬. 일반적으로 Numpy를 사용 하겠지만 Google AppEngine에 있으며 C 확장이 필요한 라이브러리를 사용할 수 없습니다.

+0

이는 이해되지 않는다. C 확장은 사용할 수 없습니까? 파이썬이 C로 쓰여 있지 않습니까? –

+2

[Google App Engine의 numpy에는 어떤 대안이 있습니까?] (http://stackoverflow.com/questions/5490723/what-alternatives-are-there-to-numpy-on-google-app-engine) –

답변

1

그냥 announced NumPy가 포함 된 Python 2.7 지원을위한 신뢰할 수있는 테스터 프로그램. 가입을 고려할 수도 있습니다.

1
class ndim:    # from 3D array to flat array 
    def __init__(self,x,y,z,d): 
     self.dimensions=[x,y,z] 
     self.numdimensions=d 
     self.gridsize=x*y*z 
    def getcellindex(self, location): 
     cindex = 0 
     cdrop = self.gridsize 
     for index in xrange(self.numdimensions): 
      cdrop /= self.dimensions[index] 
      cindex += cdrop * location[index] 
     return cindex 
    def getlocation(self, cellindex): 
     res = [] 
     for size in reversed(self.dimensions): 
      res.append(cellindex % size) 
      cellindex /= size 
     return res[::-1] 
""" how to use ndim class 
n=ndim(4,4,5,3) 
print n.getcellindex((0,0,0)) 
print n.getcellindex((0,0,1)) 
print n.getcellindex((0,1,0)) 
print n.getcellindex((1,0,0)) 

print n.getlocation(20) 
print n.getlocation(5) 
print n.getlocation(1) 
print n.getlocation(0) 
""" 
0
class ndim:    # from nD array to flat array 
    def __init__(self,arr_dim): 
     self.dimensions=arr_dim 
     print "***dimensions***" 
     print self.dimensions 
     self.numdimensions=len(arr_dim) 
     print "***numdimension***" 
     print self.numdimensions 
     self.gridsize=reduce(lambda x, y: x*y, arr_dim) 
     print self.gridsize 
    def getcellindex(self, location): 
     cindex = 0 
     cdrop = self.gridsize 
     for index in xrange(self.numdimensions): 
      cdrop /= self.dimensions[index] 
      cindex += cdrop * location[index] 
     return cindex 
    def getlocation(self, cellindex): 
     res = [] 
     for size in reversed(self.dimensions): 
      res.append(cellindex % size) 
      cellindex /= size 
     return res[::-1] 

# how to use ndim class 
arr_dim = [3,3,2,2] 
n=ndim(arr_dim) 
print "*****n.getcellindex((0,0,0,0))" 
print n.getcellindex((0,0,0,0)) 
print "*****n.getcellindex((0,0,1,1))" 
print n.getcellindex((0,0,1,1)) 
print "*****n.getcellindex((0,1,0,0))" 
print n.getcellindex((0,1,0,0)) 
print "*****n.getcellindex((2,2,1,1))" 
print n.getcellindex((2,2,1,1)) 
print 
print "*****n.getlocation(0) " 
print n.getlocation(0) 
print "*****n.getlocation(3) " 
print n.getlocation(3) 
print "*****n.getlocation(4) " 
print n.getlocation(4) 
print "*****n.getlocation(35) " 
print n.getlocation(35) 
+0

이것은 설명없이 위와 거의 동일한 대답입니다. 당신의 대답의 절박한 점과 왜 다른 대답과 다른지 설명하십시오. – blackbuild

관련 문제