0
votes
2answers
36 views

Dict and List Manipulation Python

I have two files one has key and other has both key and value. I have to match the key of file one and pull the corresponding value from file two. When all the key and value are in plain column format ...
0
votes
1answer
28 views

Python: How to create 2D array using existing lists

I have been trying to resolve this issue. I have 3 lists dev = ['Alex', 'Ashley', 'Colin'] phone = ['iPhone', 'Nexus', 'Nokia'] carrier = ['ATT', 'T-Mobile', 'MegaFon'] Is this a pythonic way to ...
1
vote
2answers
31 views

How to plot in CCDF with a list?

I can very well plot CDF and CCDF when the data is in one column. But I am a little clueless how to plot a CDF or CCDF when the data is in the below given format. The pairs in round brackets () are ...
-1
votes
2answers
19 views

parsing array in python script

please help me to parsing data in two-dimensional array in python. The value massive and dictionary inside example change every time when script run, so length massive don't do constanta. example ...
2
votes
3answers
49 views

Fastest way to count identical sub-arrays in a nd-array?

Let's consider a 2d-array A 2 3 5 7 2 3 5 7 1 7 1 4 5 8 6 0 2 3 5 7 The first, second and last lines are identical. The algorithm I'm looking for should return the ...
0
votes
2answers
11 views

how to have an array of radio buttons in post request of web2py

I have some HTML like this: <input type="radio" name="radiobutton[0]" value="1"><br> <input type="radio" name="radiobutton[0]" value="2"><br> <input type="radio" ...
1
vote
2answers
31 views

python, save data to file in loop

I would like to save arrays in loop to one file, so instead of, x = np.array([1,2,3,4,5]) y = np.array([7,6,5,2,1]) np.savetxt('out.txt', np.array([x,y])) I would like to be able to add arrays in ...
0
votes
0answers
36 views

Correct memory (and performance) management for large numpy arrays of images

I am trying to transform a large number of images in this case the shape = (42000,784) and I am running into MemoryError when I do it repeatedly in my code (i.e. if I call the function scale_xy ...
5
votes
3answers
42 views

numpy.tile a non-integer number of times

Is there a better way in numpy to tile an array a non-integer number of times? This gets the job done, but is clunky and doesn't easily generalize to n-dimensions: import numpy as np arr = ...
1
vote
1answer
28 views

Reshaping Arrays in Numpy with variables

I'm trying to take an array on numpy, add a line of code, append it to the array, and then reshape the entire array back to the translated r. While I'm attempting to use plt.imshow to display it ...
1
vote
2answers
81 views

Python: Find Nearest Neighbor [on hold]

I have gridpoints represented by the following array -90.00 -180.00 -90.00 -179.00 -90.00 -178.00 -90.00 -177.00 -90.00 -176.00 -90.00 -175.00 -90.00 -174.00 -90.00 -173.00 -90.00 -172.00 -90.00 ...
0
votes
1answer
27 views

n-dimensional sliding window with Pandas or Numpy

How do I do the R(xts) equivalent of rollapply(...., by.column=FALSE), using Numpy or Pandas? When given a dataframe, pandas rolling_apply seems only to work column by column instead of providing the ...
1
vote
3answers
25 views

Creat matrix with 2 arrays in numpy

I want to find a command in numpy for a column vector times a row vector equals to a matrix [1,1,1,1 ] ^T * [ 2,3 ] = [[2,3],[2,3],[2,3],[2,3]]
2
votes
2answers
33 views

how to load 4-bit data into numpy array

I have a binary data file that contains 8-bit complex samples--i.e. 4 bits and 4 bits for imaginary and real (Q and I) components from MSB to LSB. How can I get this data into a numpy complex number ...
1
vote
1answer
17 views

Specifying a numpy.datype to read GPX trackpoints

I want to represent a GPS track extracted from GPX file as a Numpy array. For that, each element will be of type "trackpoint", containing one datetime and three floats. I am trying to do this ...
0
votes
0answers
13 views

Using a multi function program to determine if an index's neighbor is 2 degrees larger in a 2D array

I have a 2D list of essentially any number: example = [[11,12,13,14,15], [16,17,18,19,20], [21,22,23,24,25], [26,27,28,29,30], [31,32,33,34,35]] I need to test this list using a program with two ...
0
votes
1answer
20 views

Saving/loading a table (with different column lengths) using numpy

A bit of context: I am writting a code to save the data I plot to a text file. This data should be stored in such a way it can be loaded back using a script so it can be displayed again (but this time ...
1
vote
0answers
35 views

Fastest way to remove identical sub-arrays in a nd-array? [duplicate]

Let's consider a 2d-array A 2 3 5 7 2 3 5 7 1 7 1 4 5 8 6 0 2 3 5 7 The first, second and last lines are identical. The algorithm I'm looking for should return an ...
1
vote
6answers
64 views

How to find neighbors of a 2D list in python?

I have a 2D list of only 1's and 0's: Boundaries = [ [0,0,0,0,0], [0,1,1,1,0], [0,1,1,1,1], [0,1,1,1,0], [0,0,1,0,0]] I need to test this list to check if there are any 1's surrounded by 8 other ...
0
votes
2answers
23 views

Filter numpy array by two conditions. More than one element is ambiguous

I have a numpy array which I need to filter and perform a sum on. Similar to my previous question, although this one needs to be filtered by two conditions. Need to return the sum of column 7 where ...
0
votes
1answer
31 views

How distribute repeated value in an array? [duplicate]

I'm looking to distribute all repeated value in an array. (I don't know what name is appropriate to describe that). I will explain you with an example. I have an array with duplicated values : IN : ...
0
votes
2answers
42 views

How do i make sure that every value in a 3x3 table created with 2D array is unique in its own row and column?

I have a 2D array with 9 elements in total yielding into a 3x3 table as show below : Z|A|Q Z|Q|Z Q|Z|A The table above shows an invalid 2D array as there are 2 "Z" characters in the first column ...
4
votes
1answer
35 views

python: multiply two colums of nd-arrays to get the vector of same dimensions?

I have the following code: x = np.random.randint(0,10,size=(10,2)) y = np.random.randint(0,10,size=(10,2)) x and y are 10 x 2 matrix. Now I want to multiply second column of x and y. I did z = ...
0
votes
2answers
36 views

Python recursive function to display all subsets of given set

I have the following python function to print all subsets of a list of numbers: def subs(l): if len(l) == 1: return [l] res = [] for sub in subs(l[0:-1]): res.append(sub) ...
0
votes
2answers
30 views

Array inside an array in Python [duplicate]

This is not really a question about an error. Rather, a clarification on how things work. I am putting an element(0 for example) inside an array which is also inside an array. Doing it iteratively, ...
0
votes
0answers
23 views

How to encode / decode LISP-formatted matrices in python?

I am new to python. I am using XML RPC to communicate between lisp and python and I notice that the XML encoding of matrices ( which are all I am passing back and forth ) is very verbose. For example, ...
2
votes
2answers
64 views

Copy numpy array from one (2-D) to another (3-D)

I tried to copy one array, says A (2-D) to another array, says B (3-D) which have following shape A is m * n array and B is m * n * p array I tried the following code but it is very slow, like 1 ...
1
vote
3answers
40 views

Fastest way to keep one element over two from long numpy arrays?

Let's consider a numpy array a = array([1,2,25,13,10,9,4,5]) containing an even number of elements. I need to keep only one element of the array every two at random: either the first or the ...
-1
votes
2answers
19 views

How to search for an element within a 2D array

I'd like to ask on how do I check whether my 2D array against a string for duplicate value ? //2d array sudokuBoard=[[0 for sudokuRow in range(0,int(boardSize))] for sudokuColumn in ...
1
vote
3answers
53 views

Fastest way to mix arrays in numpy?

a= array([1,3,5,7,9]) b= array([2,4,6,8,10]) I want to mix pair of arrays so that their sequences insert element by element Example: using a and b, it should result into c= ...
2
votes
1answer
26 views

insert fields of numpy structured array into mongodb

I'm currently investigating if it is possible to use structured numpy arrays more or less directly as documents for mongodb insert operations. In all examples I have found db.collection.insert(doc) ...
2
votes
1answer
37 views

How to apply the output of numpy.argpartition for 2-D Arrays?

I have a largish 2d numpy array, and I want to extract the lowest 10 elements of each row as well as their indexes. Since my array is largish, I would prefer not to sort the whole array. I heard ...
2
votes
2answers
30 views

How to add the diagonals of a matrix in Python 3.3.5

I am using numpy. My assignment is: "Write a function sumOfDiagonal that has one parameter of type list. The list is a 4x4 2-dimensional array of integers (4 rows and 4 columns of integers). The ...
0
votes
0answers
49 views

Is there any way to make this python script for processing three huge files faster? [migrated]

I have three huge files I need to process in order to rearrange the data contained within. The first file is a list of English example sentences (468,785 lines long). A typical line from this file ...
0
votes
2answers
30 views

Numpy columnwise subtraction; subtract (k,n) array from values in a (k,) array

Say I have x=np.random.random((3,10)) y=np.array([1,10,100]) and I want to subtract the values in each column of x from y. I can do this like so: np.array([y]*10).T-x However, this involves the ...
5
votes
1answer
62 views

quickly calculate randomized 3D numpy array from 2D numpy array

I have a 2-dimensional array of integers, we'll call it "A". I want to create a 3-dimensional array "B" of all 1s and 0s such that: for any fixed (i,j) sum(B[i,j,:])==A[i.j], that is, B[i,j,:] ...
0
votes
0answers
27 views

How to add element to a 2d array Python [duplicate]

I have a matrix matrix = [[0.0] * 4] * 4 it looks like: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 I'm trying to add an element to the second row, third column so that the ...
-2
votes
3answers
39 views

Python - search for string in array

I have an array of strings: ["aaa 1", "aaa 2", "bbb 2", "ccc 3", "ddd 4"] I need to search for some string in this vector, but only the first part. For example, I need the position of the strings ...
0
votes
0answers
16 views

implementing multidimensional array using list [duplicate]

The output in line 4 should be [[],[2],[],[],[]]. I m not able to understand what am I doing wrong .As I only want to append value 2 in second position of list a . But it has added 2 to all the ...
0
votes
1answer
16 views

Writing Array to txt file with requested name

I'm fairly new to Python and I'm fairly new to working with file I/O. I'm having trouble coming up with how to write an array to a new txt file whose name is entered by the user. Below is the code I ...
3
votes
1answer
27 views

RawArray from numpy array?

I want to share a numpy array across multiple processes. The processes only read the data, so I want to avoid making copies. I know how to do it if I can start with a ...
-2
votes
3answers
43 views

Generating a random number between two values from an array in Python [closed]

Let's say I have a single column float array of non-integer values: Data = [1.1 ; 1.2 ; 1.3 ; 1.4 ; 1.5] I would like to generate random numbers between two sequential values in this array and store ...
1
vote
1answer
28 views

Filter and sum different columns in a numpy array

I have a large numpy array data that I wish to filter by one column [:,8] <= radius and get the sum of a different column [:,7] So far I have the following which returns an "invalid slice" error. ...
1
vote
0answers
36 views

Getting MemoryError for a numpy array

I am analyzing some fits images using Aplpy and the images are read into arrays but I get this error message: Update: fitsfile=rgb.fits aplpy.make_rgb_cube(['R.fits', ...
1
vote
2answers
25 views

multidimensional boolean array indexing in numpy

I have a two 2D arrays, one of numbers and one of boolean values: x = array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], [ ...
2
votes
1answer
29 views

numpy.savetxt() outputs very large files

I am using numpy.savetxt() to write a numpy array to a csv file, but the file that is generated is VERY large. For example, if I create a zeros array: import numpy test = numpy.zeros((10000,10000), ...
1
vote
1answer
33 views

Check indexes in 3D numpy array

I'm trying to write code that will play a dice game called Pig through the command line with a person against the computer For the computer's player, I am using a 3D numpy array to store a game ...
1
vote
2answers
39 views

Addition of multiple arrays in python

I have a number of arrays that I wish to broadcast into a single array using addition, which I know can be simply done such that: a = numpy.array([1,2,3]) b = numpy.array9[4,5,6]) sum = a + b ...
-1
votes
2answers
37 views

Most efficient way to find objetcs in list of objects [duplicate]

I have a list or array (what is the correct term in python?) of objects. What is the most efficient way to get all objects matching a condition? I could iterate over the list and check each element, ...
19
votes
3answers
639 views

Unexpected result with += on NumPy arrays

I am creating symmetric matrices/arrays in Python with NumPy, using a standard method: x = rand(500,500) x = (x+x.T) all(x==x.T) > True Now let's be clever: x = rand(500,500) x += x.T ...