0
votes
3answers
33 views

reading CSV file and inserting it into 2d list in python

I want to insert the data of CSV file (network data such as: time,IP address, Port number ) into 2D list in Python. Here is the code: import csv datafile = open('a.csv', 'r') datareader = ...
-1
votes
2answers
31 views

remove white spaces from a 2D array using python

how can i remove white spaces in my 2D array using python..i have written my code like below.. code: MI_feature_matrix_POS = [["" for x in xrange(2)] for x in xrange(1000)] ##### perform some ...
1
vote
0answers
23 views

2D binary string pyevolve

I am new to pyevolve and GA in Python. I am trying to make a 2D binary array representing matches. Something like this: A B C 1 1 0 0 2 0 1 0 3 1 0 0 4 0 0 1 My goal is to have only one "1" in ...
-1
votes
1answer
635 views

Project Euler #11 in python

I am attempting to do project euler #11 (http://projecteuler.net/problem=11) , but I keep on incorrectly getting 51267216 as my answer and I can't figure out why. Right now I start by formatting the ...
-1
votes
1answer
57 views

some bug which i can not find for two days (output is not as expected)

from numpy import * import time import pylab as plt a=zeros([10,10]) b=ones([10,10]) dx=dy=0.1 x,y = mgrid[:1:dx,:1:dy] def add(a,b): a[1:-1,1:-1]=a[1:-1,1:-1]+b[1:-1,1:-1] data=0 print(data) ...
0
votes
5answers
49 views

How to initialise a 2D array in Python?

I've been given the pseudo-code: for i= 1 to 3 for j = 1 to 3 board [i] [j] = 0 next j next i How would I create this in python? (The idea is to create a 3 by 3 ...
3
votes
0answers
38 views

applying numpy.searchsorted over multiple axes

I'm trying to pass a 2d array of sorted values and a 1d array of values to searchsorted and have it return a corresponding 1d array of index values. I have to perform this operation many times, and ...
1
vote
2answers
45 views

Getting positions of specific values of 2d array

I need some help to detect all values (coordinates) of 2D array which verify a specific conditional. At beginning, i try to convert my 2D array in an 1D one and i get the iteration (position) in the ...
1
vote
1answer
53 views

Three 2d profiles to 3d array [duplicate]

Is there a staking method available within numpy to convert three 2d profiles into a 3d array? Where x is the straight on view, y is the horizontal view and z is the birds eye view. Whereby if in a 3d ...
0
votes
1answer
31 views

Is there a cleaner way to use a 2 dimensional array?

I'm trying to make a 2D array class, and ran into a problem. The best way I could figure out to do it was to pass get/setitem a tuple of the indices, and have it unpacked in the function. ...
1
vote
3answers
803 views

Animation with pcolormesh routine in matplotlib, how do I initialize the data?

I am trying to animate a pcolormesh in matplotlib. I have seen many of the examples using the package animation, most of them using a 1D plot routine, and some of them with imshow(). First, I wan to ...
0
votes
2answers
63 views

Passing multiple columns of a 2D array into a lambda function and returning a single column array

I am missing something simple here. I cannot figure out how to pass multiple columns of a 2D array (matrix) and output them as a single column array. Here is a simple example: import numpy as np Z ...
0
votes
1answer
84 views

Matplotlib: Quiver 2D array

i am struggling with the quiver function in python. I want to create a 2D vector field of a given 2D array containing the two components of the vectors using quiver. Given the array b: ...
0
votes
4answers
64 views

Python: storing a large matrix into a text file for later usage

In your experience, what's the best way to store a 2-dimensional array into a text file? My matrix is pretty huge, but let's use a small 3 x 3 matrix as an example. One could store it, quite ...
0
votes
2answers
35 views

How to get largest value from the 2-d array in python

suppose I have the values in 2-d array as: array = [[0.12],[0.24],[1.24],[1.45],[2.05],[0.45]] and I have to find the largest value from above, so the result should be only: 2.05 please give me the ...
0
votes
3answers
28 views

Getting inputs from the text file and storing as 2-d pattern in python

Suppose I have the text file contents as: 00 0.21 11 0.12 10 2.51 01 0.25 Where the first column is binary and the second column is float value. After reading to the text file my output ...
1
vote
1answer
40 views

Getting 2-d array pattern from user inputs in python

I want to give the user input pattern as input1: 00,01,10,11 and another input as input2: 0.1,0.2,0.24,0.5 and these inputs I am giving alternate value as one by one from these two inputs. For ...
20
votes
6answers
120k views

2D arrays in Python

What's the best way to create 2D arrays in Python? What I want is want is to store values like this: X , Y , Z so that I access data like X[2],Y[2],Z[2] or X[n],Y[n],Z[n] where n is variable. I ...
1
vote
1answer
39 views

numpy applying aggregated information across a 2D array

i have a list of agent's "health" in a 2D array: health=[[0.5,0.8],[0.1,0.5],[0.5,0.7]] and a set of actions( one per agent): actions=[[0,1],[2,0],[1,1]] (possible actions = {0,1,2} depending ...
0
votes
2answers
46 views

use list tuple as 2d index to loop through another 2d list

I built a list like this: num_rows and num cols are from list aaa for i in range(num_rows): for j in range(num_cols): if (aaa[i][j] == 0): bbb.append((i,j)) pass ...
0
votes
2answers
54 views

how to read array of numbers from text file in python

I have written code as: array = [[1.630217208498539], [0.019929319226538452]] fo = open("file.txt", "w") fo.write(str(array)) fo.close() That will save the array in .txt file, the content in the ...
0
votes
3answers
53 views

How to populate a 2-d array in python?

What's the pythonic way to rewrite the following C code? int a[16][4]; int s[16] = {1,0,2,3,0,1,1,3,3,2,0,2,0,3,2,1}; for (int i = 0; i < 16; ++i) { for (int j = 0; j < 16; ++j) { ...
1
vote
1answer
52 views

How to use the quick sort to sort by index in a list of a list

I am trying to use a quick sort to sort through a list of lists at index [1]. For example: list = [[2, 5, 3], [2, 4, 9], [0, 9, 1], [1, 1, 1], [4, 7, 5]] I want to ...
0
votes
1answer
54 views

Two dimensional array from file

Hello can somebody please, describe the algorithm of this code. Something like from pythonTutor.com, but site can't work with external files. j = 0 self.pole = [] while True: newLine = ...
1
vote
2answers
39 views

Regarding an instance of simulating the functionality of 2D arrays in Python

arr = [ "xxyyyxxxx", "xxxeeexxx", "xwwwxxxxx", ] I've seen code similar to this used to simulate 2 dimensional arrays in python by parsing the contents using for in row and for in col. Using this ...
-1
votes
1answer
2k views

Creating a list of lists Python [duplicate]

I'm used to C programming where if you wanted to allocate space 2d array you just declare it as int a[20][20]; I'm not too used to Python programming yet (I'm still in the C mindstate) I want to ...
0
votes
1answer
49 views

Averaging column 2D array python

I have a 2D arraylist data which fills with a loop like this: data.append([TrueID,rssi]) after 8 times i got this value for data: data = [['469420270013002A', -90], ['469420270005000C', ...
2
votes
1answer
130 views

Convert 2-d array of strings to float in python_removing scientific notation

How can I convert scientific notations to the original format when I use numpy.astype in x array? Here's my code: with open ('outfile.csv', 'r') as infile: reader = csv.reader(infile) ...
3
votes
1answer
213 views

Can't reshape numpy array

I have a function that is supposed to take a 1D array of integers and shapes it into a 2D array of 1x3 arrays. It then is supposed to take each 1x3 array and shift it into a 3x1 array. The result is ...
0
votes
2answers
97 views

List of 3x1 numpy arrays in Python

I'm trying to write a python function that will take a 1D array of RGB values and make a list of 3x1 arrays that represent pixels. Here is my function def RGBtoLMS(rgbValues, rgbLength): #Passing in ...
0
votes
2answers
87 views

Python randomly select an element from a 2D array and add to it

how can I randomly select an element from a 2d array and then add to it? amount_to_add = 13 my_array = [[0,0],[0,0],[0,0]] I want to randomly add 13 to one of the elements so it'd look like ...
-1
votes
2answers
69 views

while loop will not break

I have a while loop that will not break. I added a redundant conditional to make it break but that didn't work either. It is supposed to loop through a 2d array and see if it can place a block of ...
0
votes
1answer
74 views

Get rows when trying to access columns in a python script

I'm having a problem that seems like the answer would be easily explained. I'm improting from a csv file with rows and columns using the code: import csv import os import glob import numpy as np ...
0
votes
1answer
885 views

Python Index error (out of bounds) accessing element in 2D array

I'm trying to access an element of a 2d array created from data in a csv file. I can print the array fine. When I try to access the array to find a certain element (i.e. a number from 'row' 1 ...
0
votes
1answer
162 views

Combine two 2D Lists of unequal length to create one new list

I've got two 2D lists of unequal length and I'm looking to combine the two into one 2D list, when one of the parent lists falls short I'd like the loop to put in a space. For example: list1 = ...
3
votes
2answers
178 views

iterating over numpy arrays

I am having a very difficult time vectoring, I can't seem to think about math in that way yet. I have this right now: #!/usr/bin/env python import numpy as np import math grid = np.zeros((2,2)) ...
0
votes
2answers
102 views

trouble getting a specific element out of a 2D list in python

So I'm trying to remove all elements of a 2D array taken from an excel sheet with one of a few headers. values is the 2D array containing my data. One of my main problems is that not all of the rows ...
0
votes
1answer
186 views

Python issue editing tkinter canvas items in a 2darray

I'm using a raspberry pi as a communication front end for more complex devices. I'm coding it in python, and including a gui to display the information going through it. My issue involves a grid of ...
-1
votes
1answer
268 views

python checking if coordinates already exist in list

This work is for an assignment. I am working with a 2d array and so far I have found a path that I want to take through the array. There are other paths in the array and I want to be able to go ...
0
votes
3answers
371 views

python list of lists index out of range [closed]

I have read in a matrix of numbers and I am trying to work with each cell and perform tests on each one. If the number is != 0 I want to use it so if it is 0 I am currently incrementing x and y to ...
1
vote
1answer
431 views

Combine 2d-array into tuple

I want to combine two 2d-arrays into one NX2 array, but I don't know what command should I use in python. For example, a = [1.2.3] b = [4,5,6], and I want to have a new array which have the elements ...
1
vote
1answer
47 views

creating a function that makes a new universum with all elements [0] PYTHON

I want to create a function named create_empty_universum in matlab. This function will make a new universum with all elements on zero. This universum must have the n x m of a given matrix ( n length ...
0
votes
1answer
85 views

Array update anomaly in Python [duplicate]

I wrote the following code in python. Within checkd, when I update d[ii][jj], it seems as if the compiler takes its own liberties and makes all the following column entries to 1. Code: def ...
1
vote
3answers
612 views

2d array structure python

I am taking a python class and have no experience in python. The instructor only teaches documentation and refuses to give code examples. I understand C++ but I'm getting very frustrated with python ...
10
votes
4answers
434 views

Sum between pairs of indices in 2d array

Sorry, I do not know the protocol for re-asking a question if it doesn't get an answer. This question was asked a few months ago here: Numpy sum between pairs of indices in 2d array I have a 2-d ...
2
votes
2answers
135 views

How to create a Numpy 2d array with equal difference between rows?

How can I create a (48,64) Numpy array like this: i, i, i, .....,i i+0.1, i+0.1,..........,i+0.1 i+0.2, i+0.2,..........,i+0.2 . . . . i+6.3, i+6.3,..........,i+6.3 0.1 is the fixed ...
1
vote
1answer
448 views

Numpy sum between pairs of indices in 2d array

I have a 2-d numpy array (MxN) and two more 1-d arrays (Mx1) that represent starting and ending indices for each row of the 2-d array that I'd like to sum over. I'm looking for the most efficient way ...
0
votes
2answers
172 views

Inserting a new line in a 2D matrix

I have two functions that I can use to make an array: def makelist(size): list = [] for i in range(size): list = list + [None] return list def ...
1
vote
4answers
1k views

Python - getting values from 2d arrays

I have a 2d array: [[], ['shotgun', 'weapon'], ['pistol', 'weapon'], ['cheesecake', 'food'], []] How do I call a value from it? For example I want to print (name + " " + type) and get shotgun ...
0
votes
2answers
458 views

finding diagonal numbers

So I have this array here: t = [[8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8], [49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,4,56,62,0], ...