How can I decompose a list of numbers (ints) to a bigger list of a certain number of bytes using numpy?

Viewed 21

I want to use Numpy in Python to be able to input values into a function (See below).

my_func(Input, Size, byte_type="big") #Big to notate big endian or "little" to notate little endian.
            ** Code in here to answer the question **

#Calling the function. 
test = my_func([50,60], size=2, byte_type="big")
print(test)

It should print: [0, 50, 0, 60] since the size is 2 and ive inputted 50 and 60.

E.G: test = my_func([40, 50, 60], size=4, byte_type="big") print(test)

Output: [0, 0, 0, 40, 0, 0, 0, 50, 0, 0, 0, 60]

How can I achieve this?

1 Answers

hope it helps

def my_func(Input, Size, byte_type="big"):
result=[]
for item in Input:
    for i in range(Size-1):
        result.append(0)
    result.append(item)
return result

#Calling the function. 
test = my_func([50,60,20,30], Size=4, byte_type="big")
print(test)
Related