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]