3
class Matrix(db.Model):
values = db.ListProperty()
obj = Matrix()
wx = [[1,0],[0,1]]
obj.put()
データストア内にwxマトリックスを格納する方法はありますか?Google App Engineデータストア内に多次元配列を格納する方法
class Matrix(db.Model):
values = db.ListProperty()
obj = Matrix()
wx = [[1,0],[0,1]]
obj.put()
データストア内にwxマトリックスを格納する方法はありますか?Google App Engineデータストア内に多次元配列を格納する方法
行列をシリアル化する必要があります。どのようにデータをシリアル化するかは、マトリックス内のデータに基づいて照会するかどうかによって異なります。
クエリを実行しない場合は、JSON(または類似のもの)を使用してください。
from django.utils import simplejson as json
class Matrix(db.Model):
values = db.StringProperty(indexed=False)
matrix = Matrix()
# will be a string like: '[[1, 0], [0, 1]]'
matrix.values = json.dumps([[1,0],[0,1]])
matrix.put()
# To get back to the matrix:
matrix_values = json.loads(matrix.values)
あなたは「正確な行」を含む行列を照会しようとするつもりされている場合は、あなたが何かしたいと思うかもしれません:
class Matrix(db.Model):
values = db.ListProperty()
matrix = Matrix()
values = [[1,0],[0,1]]
# will be a list of strings like: ['1:0', '0:1']
matrix.values = [':'.join([str(col) for col in row]) for row in values]
matrix.put()
# To get back to the matrix:
matrix_values = [[int(col) for col in row.split(':')] for row in matrix.values]
は、