Tagged Questions
0
votes
1answer
23 views
Array update anomaly in Python
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
57 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
174 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
62 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
167 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
37 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
171 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
237 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
274 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
247 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
2k 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 ...
3
votes
1answer
2k 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
85 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
2k 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
604 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 ...