Convert function result value to over pi

Asked 2 years ago, Updated 2 years ago, 114 views

import numpy as np

u = np.random.randint(2,size=(1,100))
print(u)

print(np.size(u,1))

def turbo_enc(u):
    K = np.size(u,1)
    print(K)
    enc = np.zeros_like(u)
    enc = u
    return enc
enc1 = turbo_enc(u)
print(enc1)

def add(x,y,z):
    if((x+y+z) % 2 == 0):
        return 0
    else:
        return 1

a1 = np.array((0))
a2 = np.array((0))
def loop(u):
    global a1
    global a2
    for i in range(99):
        if(i==0):
            print(add(enc1[0][i],a1,a2),end ='')
        elif(i == 1):
            a1 = enc1[0][0]
            print(add(enc1[0][i],a1,a2),end = '')
        else:
            a1 = enc1[0][i-1]
            a2 = enc1[0][i-2]
            print(add(enc1[0][i],a1,a2),end='')
    return print(add(enc1[0][i],a1,a2),end='')

loop(u).reshape(10,10)

'add function' = 0 return if added value is even, 1 return if odd

That's the code I've written so far. I am writing 'Turbo code with interleaver', which is a college assignment, in Python. The overall process is as follows:

numpy def

2022-09-20 10:23

1 Answers

I don't know exactly what it means. First of all, I will explain the reason why the error.

def loop(u):
  #...
  return print(add(...))

In this way, the return value of the loop function passes the return value of the print function as it is. The return value of the print function is None.

Thus, loop(u) becomes None, and loop(u).Reshape(10,10) is the same as None.reshape(10,10). However, since None does not have a method called reshape, the error 'NoneType' object has no attribute 'reshape' occurred.

I think it's a difficult explanation for the questioner, but read it 10 times.


2022-09-20 10:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.