I am working with opencv mats, which are numpy arrays representing images.

Is there a way to get the sum of all x,y coordinates in a frame that is 1) most efficient 2) most pythonic?

```
frame[xpos][ypos][0] #note there are really 3 values for each pixel but i want [0]
```

doesn't:

```
np.sum(frame[:, :, 0])
```

return what you want?

Similar Questions

I have 2D list in python list = [[9, 2, 7], [9, 7], [2, 7], [1, 0], [0, 5, 4]] I would like to get union of list items if there occurs any intersection. For example [9, 2, 7], [9, 7], [2, 7] has inte

I am looking for an efficient way to compress a numpy array. I have an array like: dtype=[(name, (np.str_,8), (job, (np.str_,8), (income, np.uint32)] (my favourite example). if I'm doing something lik

I have two 2D arrays of the same size a = array([[1,2],[3,4],[5,6]]) b = array([[1,2],[3,4],[7,8]]) I want to know the rows of b that are in a. So the output should be : array([ True, True, False], d

What is the most efficient way to reshape data to fencepost with numpy? data = np.array([1, 2, 3, 4, 5]) fencepost = np.array([[1, 2], [2, 3], [3, 4], [4, 5]])

I'm trying to find an efficient way to convert from a tuple (where every 4 entries correspond to R, G, B, alpha of a pixel) to a NumPy array (for use in OpenCV). More specifically, I'm using pywin32 t

I'm beginning in Python and...coding... I m trying to do calculations on a 2D array with reject special values (i know its coordinates in the array) with array_valuesreject As example : import numpy

I created a 2d object array called that stores a String country and a double array. I'm having trouble implementing a function to retrieve the sum of cellular stats of a country through a certain peri

I have an RGBA image that I need to upscale while keeping it smooth. The catch is that I need to keep the colors exactly the way they are (background: I'm resizing a map where provinces are color-cod

Is there a more efficient way or even a method to load a 2D numpy array data[n,m] into three 1D arrays X[n*m], Y[n*m], and Z[n*m] than looping over the indices? What I did is: n = len(data[:,0]) m = l

Say I have a string text, a caret position caret and then want to find the current word (seperated by space). The way I'm currently doing it seems inefficient and I was wondering if anyone had a e

what should answer to this google-interview? What is the most efficient way to choose a random value in a stream? Given that each of them has a chance of occurring equally. Thanks.

So I am using python to call methods in a shared C++ library. I am having an issue converting a numpy 2D array to a C++ 2D array of shorts as a function input. I have a created a toy example that exhi

I have a 2D array that I want to clear and reset to 0 values. I know how to clear a vector (1D array) using Array.Clear() but I don't know the best way to clear a 2D matrix. double D = new double[10];

Say you're given the array containing: Jordan Jord Anna Rob RobJord And you want to return an array of all values that contain Jord (i.e Jord, Jordan, RobJord), what is the most efficient way to do th

I have a 2-D numpy array with 100,000+ rows. I need to return a subset of those rows (and I need to perform that operations many 1,000s of times, so efficiency is important). A mock-up example is like

Say we have an incoming stream of data of size (1,N), it is a numpy array read_data = [[foo, foo_1, foo_2]] And we want to do something with that or simply append it to a larger array. data=np.vstack

I'm new to python and I'm having a problem that I'm not able to solve. I have the following 2D array: valuearray = [['A', '21', '45'], ['A', '12', '23'], ['A', '54', '21'], ['A', '15', '54'], ['B', '2

I use an external module (libsvm), which does not support numpy arrays, only tuples, lists and dicts. But my data is in a 2d numpy array. How can I convert it the pythonic way, aka without loops. >

I want to get the intersecting (common) rows across two 2D numpy arrays. E.g., if the following arrays are passed as inputs: array([[1, 4], [2, 5], [3, 6]]) array([[1, 4], [3, 6], [7, 8]) the output

I am apply an operation on a moving window of constant size across a 2D array. Is there an efficient vectorize-like operation I can implement to do this without looping in Python? My current structure

Given an array of the array [X,Y]: a=[[1,2],[2,2],[3,2],[4,2],[5,2],[6,2]] What is the most efficient way to sum all the Y digits for 2<=X<4?

You're given an array of size n, containing arbitrary boolean values. What is the fastest way to return the index of a random TRUE value. The algorithm should randomly return any one of the indices c

Using the Twitter API, what would be the most efficient way to find which users favorited a specific tweet? And also it possible to do this in retrospective, or must the streams be tapped prior the fa

I want to describe the following problem using Z3. int []array1=new int[100]; int []array2=new int[100]; array1[0~99]={i0, i1, ..., i99}; (i0...i99 > 0) array2[0~99]={j0, j1, ..., j99}; (j0...j99 &

Pretty simple scenario. I have a web service that receives a byte array that is to be saved as a particular file type on disk. What is the most efficient way to do this in C#?

Here is my code: var myArray = {}; myArray[abc] = new Array(); myArray[def] = new Array(); myArray[abc][0] = John; myArray[abc][1] = Mary; myArray[abc][2] = Jack; var letter = ; var

I'm writing a 2D iPad application where the main portion of the screen will be filled using 16x16 pixel tiles, so 3600 in total. The display doesn't have to update particularly smoothly (and only upda

I have a list of X items. I want the first 10 to be randomized. Then, the 2nd 10 items to be randomized. Then the 3rd. What's the most efficient way to do this?

Bear with me as I am very new to Python. Basically I am looking for the most efficient way to search through a multi-dimensional list. So say I have the following list: fruit = [ [banana, 6], [apple,

I want to get a list but the last and the first elements. What is the most efficient way? middle = init . tail or: middle = tail . init And in the case of drop the n-first elements and the n-last el

This piece of code updates all elements of a 2d array with some random value, is there any another simple and short code to solve this problem? val terrainTypes = TerrainBlockType.values (0 until widt

I have a C array like: char byte_array[10]; And another one that acts as a mask: char byte_mask[10]; I would like to do get another array that is the result from the first one plus the second one us

I have a function gen() which returns a numpy array of nElements number of floats. I'm looking for a more Pythonic (one liner?) way to do the following: a = zeros((nSamples, nElements)) for i in xrang

How can i store a list within a numpy 2d array? import numpy A = numpy.empty([5,5], dtype=**?**) What should be the dtype for a variable list kind of thing here? or Is there a different way to implem

I need some help with this problem. I have to sum all integers in a 2d array using recursion. Below is what I have managed to do on my own, but I'm stuck. This code generates the sum 14, which should

Given a 2D numpy array: 00111100110111 01110011000110 00111110001000 01101101001110 Is there an efficient way to replace runs of 1 which are >= N in length? For example, if N=3 00222200110222 0222

All these do it, but what is the most efficient way? $(selector).html(''); $(selector).text(''); $(selector).children().remove();

I am working with a 2D NumPy array. I would like to get the (column, row) index, or (x, y) coordinate, if you prefer thinking that way, from my 2D array that meets a boolean condition. The best way I

What is the most efficient/elegant way to filter all paths by a base path? I have a path list and a base path, and I want a to get a list of paths that are children of the base path: public IList<s

I have a 3D-numpy array of a gray image, which looks something like this: [[[120,120,120],[67,67,67]]...] Obviously I have every R G and B the same because it is a gray image - this is redundent. I w

I have Image_1.jpg.I got Image Pixel Value in 2D Array from Image_1.jpg.I have set First 8*8 blocks Value of 2D Array as following. 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16

EDIT: Thank you all for the good solutions, I think if I'd had to pick one, it would be A[:,[0]] I collected 7 approaches now and put them into an IPython notebook. The timeit benchmarks are not supri

I need suggestions about storing a 2D array in a binary file. I need it to be extensive, to be able to add new rows and columns very fast. So far i've come up with this approach: i allocate a fixed si

Based on my question Fastest way to approximately compare values in large numpy arrays? I was looking for ways to split an array as I wanted. I have a sorted array (2D, sorted by values in one column)

I have a 3D array that represents density values over cartesian space. To get a 2D image I just sum over one of the axes using sum(array,2) and then use the matplotlib function imshow(array2D) to obta

What are the advantages and disadvantages of storing Python objects in a numpy.array with dtype='o' versus using list (or list of list, etc., in higher dimensions)? Are numpy arrays more efficient in

I have a list that contains nested lists and I need to know the most efficient way to search within those nested lists. e.g., if I have [['a','b','c'], ['d','e','f']] and I have to search the entire

I have a 2D numpy array... there are some values in the image and rest is sparse. For linear imterpolation, I want to take the first column of the array. See where the values are present and do the li

I have a 2D NumPy array and would like to replace all values in it greater than or equal to a threshold T with 255.0. To my knowledge, the most fundamental way would be: shape = arr.shape result = np.

I am looking for a fast formulation to do a numerical binning of a 2D numpy array. By binning I mean calculate submatrix averages or cumulative values. For ex. x = numpy.arange(16).reshape(4, 4) would