About 353,000 results
Open links in new tab
  1. python - Understanding the map function - Stack Overflow

    Jun 11, 2012 · In Python 2 map(), will iterate (go through the elements of the lists) according to the longest list, and pass None to the function for the shorter lists, so your function should look for None and handle them, otherwise you will get errors. In Python 3 map() will stop after finishing with the shortest

  2. python - Most efficient way to map function over numpy array

    Jun 13, 2022 · But first let's state the obvious: no matter how you map a Python-function onto a numpy-array, it stays a Python function, that means for every evaluation: numpy-array element must be converted to a Python-object (e.g. a Float).

  3. Getting a map() to return a list in Python 3.x - Stack Overflow

    map(func, *iterables) --> map object Make an iterator that computes the function using arguments from each of the iterables. Stops when the shortest iterable is exhausted. "Make an iterator" means it will return an iterator. "that computes the function using …

  4. python - How to do multiple arguments to map function where …

    we want to apply map function for an array. map(add, [1, 2, 3], 2) The semantics are I want to add 2 to every element of the array. But the map function requires a list in the third argument as well. Note: I am putting the add example for simplicity. My original function is much more complicated.

  5. python - map() a function with a numpy array and lists as …

    Oct 17, 2021 · I would like to vectorize a function which applies some simple filtering logic to a numpy array: import numpy def func(arr, a, b): sub = arr[arr[:,a] > b] mean = numpy.mean(sub, axis=0...

  6. Mapping arrays in Python using map, lambda, and functional …

    I'm trying to understand how functional programming languages work, and I decided to take the approach of program in a functional way in python, as it is the language in which I feel more comfortable. I'm trying to, given an array of arrays and a function with 2 params, get two sentences with the two elements in each array.

  7. python - Squaring all elements in a list - Stack Overflow

    That's why you can **2 an entire array there. Other possible solutions would be map-based, but in this case I'd really go for the list comprehension. It's Pythonic :) and a map-based solution that requires lambdas is slower than LC.

  8. python - Mapping a NumPy array in place - Stack Overflow

    The array is a reference to the image pixel values, not a copy of it, so I need to change the array I got from pygame if I want my image/sprite to be modify in the scene. That said, this is my very first time with pynum, so if I missed something, you are welcome to rectify my understanding!

  9. python - Plotting a 2D heatmap - Stack Overflow

    Oct 16, 2022 · Using Matplotlib, I want to plot a 2D heat map. My data is an n-by-n Numpy array, each with a value between 0 and 1. So for the (i, j) element of this array, I want to plot a square at the (i, j)

  10. What are Python's equivalent of Javascript's reduce(), map(), and ...

    Jun 30, 2015 · map requires the creation of a lambda function for the computation, which is visually noisy." I would add the same goes for filter. e.g. let's say I want to map and filter over a list to return the square of the items in the list, but only the even ones (this is an example from the book). Using the accepted answer's method of using lambdas:

Refresh