-1
def encode(line):
        el = [ord(c) for c in line]
        while len(el) is not 100:
            el.append(0)
        el = np.asarray(el).reshape(10,10)
        return el
with open("C:\\Users\\KIIT\\Desktop\\test.txt") as f:
        lines = f.readlines()[0:1]
        for line in lines:
            el = encode(line)
print(el)

For this code my computer is working fine with speed. But when I increase the size of the array if, the computer is stop working and I have to restart it.

the code for which it is not working:

def encode(line):
        el = [ord(c) for c in line]
        while len(el) is not 784:
            el.append(0)
        el = np.asarray(el).reshape(28,28)
        return el
with open("C:\\Users\\KIIT\\Desktop\\test.txt") as f:
        lines = f.readlines()[0:1]
        for line in lines:
            el = encode(line)
print(el)
Sreeram TP
  • 11,346
  • 7
  • 54
  • 108

1 Answers1

2

You're falling foul of the integer cache in Python. is not is not the way to test for equality of integers. However, it will work for values between -5 and 256 because Python maintains a cache of objects for these values.

Change: while len(el) is not 784:

To: while len(el) < 784:

roganjosh
  • 12,594
  • 4
  • 29
  • 46