# function « numpy « Python Data Type Q&A

Home
Python Data Type Q&A
 1 array 2 date 3 dictionary 4 Format 5 integer 6 List 7 numpy 8 regex 9 string 10 tuple
 Python Data Type Q&A » numpy » function

### 1. Python: Numpy array help. Is there a function to return the index of something in an array?    stackoverflow.com

I know there is a method for python list to return the first index of something

``````l = list(1,2,3)
l.index(2)
>>>  1
``````
Is there something like that for numpy arrays? Thanks for your help :) ...

### 2. How can I create a numpy array holding values of a multi-variable function?    stackoverflow.com

I want to create an array holding a function `f(x,y,z)`. If it were a function of one variable I'd do, for instance:

``````sinx = numpy.sin(numpy.linspace(-5,5,100))
``````
to get `sin(x)` for `x` in `[-5,5]` How ...

### 3. Mapping functions of 2D numpy arrays    stackoverflow.com

I have a function `foo` that takes a NxM numpy array as an argument and returns a scalar value. I have a AxNxM numpy array `data`, over which I'd like ...

### 4. Mapping function to numpy array, varying a parameter    stackoverflow.com

First, let me show you the codez:

``````a = array([...])
for n in range(10000):
func_curry = functools.partial(func, y=n)
result = array(map(func_curry, a))
do_something_else(result)
...``````

### 5. How can I build a polynomial lambda function from an list of coefficients?    stackoverflow.com

I have an list of coefficients that correspond to a polynomial expression, ie: `[1,2,0]` corresponds to `x^2 + 2x + 0`. I would like to put an arbitrary length array of ...

### 6. Broadcasting a python function on to numpy arrays    stackoverflow.com

Let's say we have a particularly simple function like

``````import scipy as sp
def func(x, y):
return x + y
``````
This function evidently works for several builtin python datatypes of `x` and ...

### 7. Passing Numpy arrays to a C function for input and output    stackoverflow.com

Oh my word I'm a fool. I was simply omitting the second and third arguments when calling the function. Like a fool. Because that's what I am. Original silly question follows: This seems like it must ...

### 8. A numpy.arange style function with array inputs    stackoverflow.com

I have numpy arrays of start indices and end indices from which I'd like to construct a flattened array of ranges. e.g. with inputs

``````s = np.array([1,2,3])
e = np.array([4,5,10])
``````
and output
``````array([1,2,3,2,3,4,3,4,5,6,7,8,9])
``````
any way to do ...

### 9. NumPy: Apply an index selecting function to multiple axes    stackoverflow.com

I'm writing code to optimize quantities that depend on a variable number of parameters. For the optimization I would like to apply index selecting functions such as numpy.argmax and numpy.argmin ...

### 10. Minimizing python function that has numpy array as argument    stackoverflow.com

I'm new to python, and I have the following problem: I am trying to minimize a python function that has a numpy array as one of its arguments. When I use ...

### 11. "If" function used for array in Python    stackoverflow.com

I have this function:

``````def q(x,y):
r2 = (x/2.)**2 + (2.0*y)**2
if (r2 > 0.04):
return 0.
...``````

### 12. Writing functions that accept both 1-D and 2-D numpy arrays?    stackoverflow.com

My understanding is that 1-D arrays in numpy can be interpreted as either a column-oriented vector or a row-oriented vector. For instance, a 1-D array with shape `(8,)` can be ...

### 13. How to "reduce" a numpy array using a costum binary function    bytes.com

I know there must be a simple method to do this. I have implemented this function for calculating a checksum based on a ones complement addition: def complement_ones_checksum(ints): """ Returns a complements one checksum based on a specified numpy.array of dtype=uint16 """ result = 0x0 for i in ints: result += i result = (result + (result >16)) & 0xFFFF return ...