0
votes
3answers
23 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
24 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 ...
1
vote
1answer
34 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
30 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
45 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
45 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
41 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
41 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
34 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
1k 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
43 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
84 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
99 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
63 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
69 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
65 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
2answers
468 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
1answer
72 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
661 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
133 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
146 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
74 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
98 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
244 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 ...
-1
votes
1answer
498 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 ...
0
votes
3answers
304 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
347 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
45 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
82 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
524 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 ...
9
votes
4answers
411 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
130 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
378 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
140 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
960 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
421 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], ...
2
votes
3answers
566 views

Manipulating indices to 2d numpy array

I can index a 2d numpy array with a tuple or even a list of tuples a = numpy.array([[1,2],[3,4]]) i = [(0,1),(1,0)] # edit: bad example, should have taken [(0,1),(0,1)] print a[i[0]], a[i] (Gives 2 ...
0
votes
3answers
416 views

Reducing duplicates in Python list of lists

I am writing a program that reads in a number of files and then indexes the terms in them. I am able to read in the files into a 2d array (list) in python, but then I need to remove the duplicates in ...
2
votes
1answer
3k views

2D array plotting in matplotlib

I was trying to plot a 2D array vs a 1D array with pyplot. I can do that with no problems and columns in the 2D array are treated like two different sets of Y datas, which is what i want. What i don't ...
5
votes
1answer
4k views

numpy - 2d array indexing

According to docs numpy's default behaviour is to index arrays first by rows then by columns: a = numpy.arange(6).reshape(3,2) [[0 1] [2 3] [4 5]] print a[0][1] # is 1 I want to index the array ...
1
vote
1answer
109 views

What's going on here? Repeating rows in random list of lists

I expected to get a grid of unique random numbers. Instead each row is the same sequence of numbers. What's going on here? from pprint import pprint from random import random nrows, ncols = 5, 5 ...
4
votes
5answers
5k views

Python - best way to set a column in a 2d array to a specific value

I have a 2d array, I would like to set a column to a particular value, my code is below. Is this the best way in python? rows = 5 cols = 10 data = (rows * cols) *[0] val = 10 set_col = 5 for row in ...
8
votes
7answers
666 views

What is meant by 2D array support?

I read that Python does not actually support 2D arrays but rather an array of an array. I understand the array of an array thing but what does it mean by supporting 2D arrays? In C a 2D array is ...
1
vote
4answers
1k views

Is there a Python module/recipe (not numpy) for 2d arrays for small games

I am writing some small games in Python with Pygame & Pyglet as hobby projects. A class for 2D array would be very handy. I use py2exe to send the games to relatives/friends and numpy is just ...
19
votes
6answers
113k 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 ...