1
vote
2answers
27 views

Optimal way to append to numpy array

I have a numpy array and I can simply append an item to it using append, like this: numpy.append(myarray, 1) In this case I just appended the integer 1. But is this the quickest way to append to ...
-1
votes
3answers
35 views

Indexing lists with arrays in python

I want to index each element of a list using an array. For example, I want to use list[arr] = 1, where arr is an array instead of list[ind] = 1 where ind is a number index. Using Dictionary data ...
0
votes
0answers
13 views

How to add different arrays from the center point of an array in Python/NumPy

following on from " Adding different sized/shaped displaced NumPy matrices ", I want to extend the code, so that I can do the addition at the center import numpy as np #two 3d arrays, of different ...
0
votes
0answers
29 views

Average array by intervals

I have a 2D array of floats which looks like this (data here): As you can see, the values are not unique and a single x value can have several y values. I'd like to produce a single average curve ...
-1
votes
3answers
18 views

Python Remove Column from Numpy Array based on some Condition

The Title says it all. Suppose I have a numpy array containing values summing up to 1. [0.5 0.3 0.1 0.05 0.03 0.01] And I would want to remove all Values of the array which are smaller than ...
0
votes
0answers
20 views

Assigning elements in array to certain calendar dates input by user

Here is part of my code where this would be used. The user is prompted for any year, month, and day. The program returns the day of the week I want to be able to print corresponding section number ...
-3
votes
0answers
33 views

How to compare dictionaries or arrays with each other- python

I have to create a simulation of a football season using python, in which all the teams have to play each other twice (home and away) and depending on certain variables like cost of team, the winners ...
2
votes
2answers
55 views

Multiprocessing passing an array of dicts through shared memory

The following code works, but it is very slow due to passing the large data sets. In the actual implementation, the speed it takes to create the process and send the data is almost the same as ...
-1
votes
0answers
21 views

pandas multiindexing dataframe from index and repetable items from column

for data: x y z Input Sequence 1 5.6000 0.8519 -6.5000 2 5.1730 0.7151 -6.5000 3 5.6000 ...
1
vote
3answers
35 views

Find specific varible in array inside array

I want to search an array if it contains an variable "Foo" details={u'firstName': u'Test', u'activeSubscriptions': [{u'productCode': u'BBB', u'name': u'Bar'}, {u'productCode': u'FFF', u'name': ...
1
vote
2answers
17 views

Python .extend splitting Characters unnecessarily

colourImgArray = [] sizeList = soup.find('table', {'class' :'table-sku'}) for sizeTD in sizeList.findAll('td', {'class' :'name'}): for ...
0
votes
1answer
22 views

Select 'area' from a 2D array in python

Is there a way to select a particular 'area' of a 2d array in python? I can use array slicing to project out only one row or column but I am unsure about how to pick a 'subarray' from the large 2d ...
0
votes
2answers
37 views

Compare two numpy arrays by first Column and create a third numpy array by concatenating two arrays

I have two 2d numpy arrays which is used to plot simulation results. The first column of both arrays a and b contains the time intervals and the second column contains the data to be plotted. The two ...
0
votes
1answer
20 views

Defining large list-within- list array

I'm attempting to make a Tetris clone in python, and want to make my code more efficient. I want a variable named board to be a 20 * 10 array with False in each cell, a 2 by 2 example of this being ...
0
votes
2answers
34 views

Since Python lists can hold elements of different types, is accessing an element worse than constant time?

Languages such as C++ require that an array hold elements of a single type. As I understand it, knowing the size of each element allows for pointer arithmetic, making access of a particular element ...
0
votes
2answers
32 views

How to truncate a numpy array for values greater than a specified value?

Similar to this Matlab question, I am wondering how to truncate a numpy array by cutting off the values greater than a certain threshold value. The values of the array in question are in ascending ...
1
vote
2answers
34 views

How to convert array string to an array in python [duplicate]

Im trying to convert an array that ive stored in a mysql database (as a string) to a standard array in python an example of what I mean is: This is what i get from the database: ...
3
votes
1answer
37 views

Selecting rows from two nump.nd arrays and insert 0 for the missing match

I have two nd.numpy arrays named 'a' and 'b', I want to select only certain rows from array 'b' based on the comparison with 'a' and insert 0 for the rows if a match is not found. I did the first ...
2
votes
1answer
47 views

How to send an array by i2c?

I've been trying for several days now to send a python array by i2c. data = [x,x,x,x] # `x` is a number from 0 to 127. bus.write_i2c_block_data(i2c_address, 0, data) bus.write_i2c_block_data(addr, ...
1
vote
1answer
56 views

make a matrix out of 1-D arrays of array objects

I would like to convert my 1-D arrays of array objects in a numpy matrix to perform the sum of its elements over the rows. The 1D arrays of array is: out = array([[array([0]), array([ 23.]), ...
0
votes
1answer
85 views

numpy delete an array value (logical zero)

The short story is: I am trying to delete a precise point in an array, by using a logical zero or any other way. I am starting with some points' coordinates which define a wing. With them, I am ...
3
votes
3answers
47 views

How do I return a repeated item from an array only once?

I have a large array, part of which looks like this ... [u'3767' u'SS14 3HG'] [u'3768' u'SS14 3HG'] [u'3769' u'SS14 3HG'] [u'3770' u'SS14 3HG'] [u'3771' u'SS14 3HG'] [u'3772' u'SS14 3HG'] ...
-2
votes
5answers
42 views

Python fill a dict with list of values [closed]

I am looking for a simple way to put all elements of a given array as values in a dictionary. At the moment it looks like this: for i, e in enumerate(list): passiv_dict = { ...
-4
votes
3answers
41 views

For loop not adding iterating no in list [closed]

I am a Python beginner. I am trying to solve this algorithm problem. You are given an array of integers. You should find the sum of the elements with even indexes (0th, 2nd, 4th...) then multiply ...
1
vote
1answer
20 views

Efficient summed Area Table Calculation with Numpy

I'm trying to calculate a summed area table of a feature count matrix using python and numpy. Currently I'm using the following code: def summed_area_table(img): table = ...
0
votes
2answers
40 views

Python - choose a single element with some property from an array

I have come across this case a few times now: I have an array which contains an element I want and I want to select that element without knowing the index, and instead knowing some desired property ...
0
votes
4answers
59 views

All possible random tiles in 2048(Stupid issue)

I am trying to make a function that takes in a 2048 board(nested lists making a 4 by 4 grid), like this, [[0, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]] Note: I know this isn't a ...
2
votes
2answers
47 views

make 1 dimensional array of strings with elements seperated by commas from 2 d array in numpy

I need to make a 1D numpy array from a 2D array, such that the elements within the 2 columns are joined and separated and the data type is a string. I can do the opposite function with np.split, but ...
-2
votes
4answers
44 views

convert array to dict

I want to convert a list to a dictionary: products=[['1','product 1'],['2','product 2']] arr=[] vals={} for product in products: vals['id']=product[0] vals['name']=product ...
2
votes
2answers
60 views

Python tuple to C array

I am writing a C function that takes a Python tuple of ints as an argument. static PyObject* lcs(PyObject* self, PyObject *args) { int *data; if (!PyArg_ParseTuple(args, "(iii)", &data)) ...
0
votes
2answers
55 views

initialize numpy array with named tuples

I'm trying to initialize a NumPy array that contains named tuples. Everything works fine when I initialize the array with empty data and set that data afterwards; when using the numpy.array ...
1
vote
1answer
35 views

Finding the correspondence of data by interpolation

I have a catalogue of data and I want to use it in my MCMC code. What is crucial is the speed of implementation, in order to avoid slowing down my Markov chain monte carlo sampling. The problem: In ...
0
votes
1answer
27 views

In python what is the most efficient way to get the sum of values in a 2d numpy array?

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? ...
0
votes
0answers
14 views

Plotting a numpy array in healpy

I am attempting to produce a beam on a healpix map, using healpy. For starters, I would like to be able to produce a 2D gaussian in a mollweide projection, but I really don't know where to begin. I ...
1
vote
2answers
30 views

subtract column of scipy.sparse matrix from a vector

I'm trying to find a way to subtract a column of a scipy.sparse matrix from a numpy vector but I can't seem to find a way to do it without changing the shape of the vector. This is what I have so far: ...
3
votes
3answers
43 views

finding identical rows and columns in a numpy array

I have a bolean array of nxn elements and I want to check if any row is identical to another.If there are any identical rows, I want to check if the corresponding columns are also identical. Here is ...
1
vote
2answers
15 views

Custom arrangement of NumPy array elements

I have a NumPy array 'data' as follows: data = np.array([ [0.0, 30.0, 60.0, 90.0, 120.0, 150.0, -180.0, -150.0, -120.0, -90.0, -60.0, -30.0], [0.0, 30.0, 60.0, 90.0, 120.0, 150.0, -180.0, -150.0, ...
3
votes
1answer
38 views

Manipulating array elements in NumPy

I have a given array 'a' as follows: import numpy as np a = np.arange(-100.0, 110.0, 20.0, dtype=float) #increase 20 a = np.tile(a, 4) a = a.reshape(4,11) [[-100. -80. -60. -40. -20. 0. ...
0
votes
2answers
44 views

Python 2.7, populating tables with arrays

I need to populate different rows of a table with the correct field, I am currently populating one column using an array, the results of which are gathered by parsing a file (network capture ...
0
votes
1answer
38 views

Using numpy any() in bool array of arrays

I have a list of lists which are composed by bools, let's say l = [[False, False], [True, False]], and I need to convert l to a numpy array of arrays of booleans. I converted every sublist into a bool ...
0
votes
1answer
33 views

Strange behavior with nested arrays

Suppose I have a nested array, foo: >>> foo = [[" ", " "], [" ", " "]] Say I want to change element 0 of array 0. I would do it like this: >>> foo[0][0] = "a" >>> print ...
0
votes
4answers
27 views

Python .join() with a 2d array

Say I have this array: foo = [["a", "b"], ["c", "d"]] If I want to print the elements of the inner arrays, I would do something like this: for array_ in foo: for element in array_: ...
3
votes
2answers
24 views

More than one module for lambdify in sympy

I am trying to make lambdify understand to expect more than one type of input using the modules keyword argument. According to the source code of lambdify ...
0
votes
1answer
43 views

f2py: how to pass 2 dimension list to fortran 77

I have trouble passing 2D arrays to fortran. I want to combine a bunch of not overlapping spectra. First I select the points on the x-axis, then I interpolate all data to this new, common grid. I ...
0
votes
2answers
33 views

Perform operations on elements of a NumPy array

Is there a faster/smarter way to perform operations on every element of a numpy array? What I specifically have is a list of datetime objects like, e.g.: hh = np.array( [ dt.date(2000, 1, 1), ...
2
votes
1answer
33 views

numpy.subtract but only until difference reaches threshold - replace numbers smaller than that with threshold

I want to subtract a given value from each element in my numpy array. For example, if I have a numpy array called a_q, and variable called subtract_me, then I can simply do this: result = ...
1
vote
0answers
27 views

algorithm used inside for reshape of matrix (2d array) in numpy

basic link where numpy implemented reshape is https://github.com/numpy/numpy/blob/master/numpy/core/fromnumeric.py but how it reshape algorithm i didn't understand , can any body write algorithm to ...
-2
votes
0answers
26 views

convert array without commas separation to one's with [closed]

I have a function that return a numpy array this way: A = [[4] [1] [1] [4] [5] [1] [2] [4] [2]] I have a function that needs to get A this way: B = [[4], [1] ,[1], [4], [5], [1], [2], [4], [2]] ...
1
vote
2answers
37 views

Return multiple vars: list/tuple

I have a function which must return many values (statistics) for other function to interact with them. So I thought about returning them inside a list (array). But then I wondered: should I do so ...
0
votes
2answers
25 views

check how many elements are equal in two numpy arrays python

I have two numpy arrays with number (Same length), and I want to count how many elements are equal between those two array (equal = same value and position in array) A = [1, 2, 3, 4] B = [1, 2, 4, 3] ...