我有一个 236 x 97 维的矩阵。当我在 Python 中打印矩阵时,它的输出不完整,矩阵中间有 ......。
我尝试将矩阵写入测试文件,但结果完全一样。 我无法发布屏幕截图,因为我的声誉不够,如果我选择其他标记选项,将无法正确显示。 谁能解决这个问题?
def build(self):
self.keys = [k for k in self.wdict.keys() if len(self.wdict[k]) > 1]
self.keys.sort()
self.A = zeros([len(self.keys), self.dcount])
for i, k in enumerate(self.keys):
for d in self.wdict[k]:
self.A[i,d] += 1
def printA(self):
outprint = open('outputprint.txt','w')
print 'Here is the weighted matrix'
print self.A
outprint.write('%s' % self.A)
outprint.close()
print self.A.shape
请您参考如下方法:
假设您的矩阵是一个 numpy 数组,您可以使用 matrix.tofile(<options>)按照记录将数组写入文件 here :
#!/usr/bin/env python
# coding: utf-8
import numpy as np
# create a matrix of random numbers and desired dimension
a = np.random.rand(236, 97)
# write matrix to file
a.tofile('output.txt', sep = ' ')
