Issue
This Content is from Stack Overflow. Question asked by andyon98
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?
Solution
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)
This Question was asked in StackOverflow by andyon98 and Answered by Jeson Pun It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.