About 196,000 results
Open links in new tab
  1. Python: Can a function return an array and a variable?

    Oct 22, 2013 · def my_function(): my_array = np.array([1.,2.,3.]) my_variable = 99. return my_array,my_variable my_function() so that the values calculated in the function can be used later in the code? The above ignores the values calculated in the function. I tried returning a tuple {my_array, my_variable} but got the unhashable type message for np.array

  2. Python: Returning array values from a function - Stack Overflow

    Sep 9, 2019 · I'm trying to understand how to use functions properly. In this code, I want to return 2 arrays for pupil names and percentage scores. However I am unable to return the array variables from the first function. I've tried using different ways of defining the arrays (with and without brackets, both globally and locally)

  3. Meaning of list [-1] in Python - Stack Overflow

    Sep 19, 2018 · So, if you wanted the last element in array, you would call array[-1]. All your return c.most_common()[-1] statement does is call c.most_common and return the last value in the resulting list, which would give you the least common item in that list. Essentially, this line is equivalent to: temp = c.most_common() return temp[len(temp) - 1]

  4. python - How can I return an array from a function? - Stack Overflow

    Nov 20, 2023 · When I try to return the array from the function instead of getting the newly appended array I just get an empty one []. I know the rest of the code works when it is all inside one function however I have been tasked with specifically defining the values outside the function and only appending inside the function.

  5. Returning an Array Using Recursion in Python 3 - Stack Overflow

    Oct 11, 2016 · else: for i in range(0,n+1): formula=((x1)**(n-i))*((x2)**(i)) list.append(formula) return mapfeature_binominal_array(x1,x2,n-1,list) A recursive function call is just like any other function call; you still need to do something with the result of that function call; the value it returns does not automatically propagate to be the return value ...

  6. Python: find position of element in array - Stack Overflow

    For your first question, find the position of some value in a list x using index(), like so:. x.index(value) For your second question, to check for multiple same values you should split your list into chunks and use the same logic from above.

  7. How to return array from C++ function to Python using ctypes

    Feb 15, 2013 · The C++ function should return a pointer to an array. Unfortunately I haven't figured out, how to access the array in Python. I tried numpy.frombuffer, but that was not successful. It just returned an array of arbitrary numbers. Obviously I didn't used it correctly. Here is a simple example with an array of size 10: Content of function.cpp:

  8. python - How can I find the index for a given item in a list? - Stack ...

    View the answers with numpy integration, numpy arrays are far more efficient than Python lists. If the list is short it's no problem making a copy of it from a Python list, if it isn't then perhaps you should consider storing the elements in numpy array in the first place. –

  9. How do I select elements of an array given condition?

    Note that numpy.where will not just return an array of the indices, but will instead return a tuple (the output of condition.nonzero()) containing arrays - in this case, (the array of indices you want,), so you'll need select_indices = np.where(...)[0] to get the result you want and expect. –

  10. python - Find the indices of elements greater than x - Stack …

    Dec 5, 2012 · X[np.array(a)>4]#X needs to be np.array as well Explanation: np.array converts a to an array. np.array(a)>4 gives a bool array with all the elements that should be kept. And X is filtered by the bool array so only the elements where a …

Refresh