Answer the question
In order to leave comments, you need to log in
How to make return return multiple arrays?
Hello.
The question is this: I am multiplying the first, second, third, ..., j-th values of one array by each of the elements of another array. As a result, when printing, j arrays are obtained. But I can’t figure out how exactly to stuff j arrays into return? When called in a subsequent function, all operations occur only with the first of them.
def getcoordinates(array1, array2):
"""Перемножаем [cначала первое, потом второе, ..., j-ое] значения первого массива на каждый из элементов второго массива."""
for j in array1:
array3 = [j * i for i in array2]
print(array3)
return array3
def buildgraph(array3, array1):
print(array3) #тут выводится только первый массив вместо j-ого количества массивов
Answer the question
In order to leave comments, you need to log in
return terminates the execution of the function.
For return to return j arrays, you must then return a two-dimensional array. To do this, we declare an array before for; arrayRes=[]
, and in the loop, instead of return, we add each array3 to our array: arrayRes.append(array3)
, and at the end of the function, after the loop, we writereturn arrayRes
You can also return generators, like this:
def func():
for i in xrange(10):
yield xrange(10)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question