Tagged Questions
0
votes
4answers
43 views
how can i set a variable in a array in python?
i have the problem where i set a variable but it creates a new one instead, i am not quite sure what is going on here. I have tried using global, setting the variables first and tried to use a tupple ...
1
vote
1answer
49 views
How to visualise the number of dimensions in an array for python numpy
I am experimenting the different dimensions one can have in an array using ndim().
x=np.arange(0,100,1).reshape(1,20,5)
The shape is:
[[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]
[15 ...
2
votes
3answers
61 views
Using nested for loops to evaluate function at every coordinate - python
I am trying to use a nested for loop to evaluate function f(r) at every combination of 2D polar coordinates.
My current code is:
r = np.linspace(0, 5, 10)
phi = np.linespace(0,2*np.pi, 10)
for i in ...
2
votes
2answers
33 views
How to make a scipy array from custom data format?
Warning: Python newbie...
I have text that looks like this, which came from a database query:
2000;"SCHOOLS OF MEDICINE";416765.0
2000;"SCHOOLS OF ARTS AND SCIENCES";36000.0
2000;"SCHOOLS OF ...
0
votes
2answers
36 views
Passing Arrays from Python to Fortran (and back)
Background:
My program currently assembles arrays in Python. These arrays are connected to a front-end UI and as such have interactive elements (i.e. user specified values in array elements). These ...
4
votes
5answers
51 views
How to split a string at line breaks in python?
I want to copy some tabular data from Excel into a python array. That is, user willselect a range in an Excel table, press "Copy" (CTRL+C) so that the range will be copied to clipboard. Then I will ...
2
votes
3answers
27 views
declaring and initialising 2d array in python
I am declaring multidimensional array in python
Nbrs[23][2] = [[1, 1], [1, 2], [2, 1],
[2, 3], [3, 2], [1, 3],
[3, 1], [1, 4], [3, 4],
[4, 3], [4, 1], ...
2
votes
2answers
40 views
How to vectorize a set of items in python
I am trying to take a set of arrays and convert them into a matrix that will essentially be an indicator matrix for a set of items.
I currently have a array of N items
A_ = [A,B,C,D,E,...,Y,Z]
...
3
votes
1answer
43 views
Fast interpolation over 3D array for 3D origin x
This problem is similar to a former problem answered Fast interpolation over 3D array, but cannot solve my problem.
I have a 4D array with dimensions of (time,altitude,latitude, longitude), marked as ...
0
votes
1answer
22 views
Most efficient way to determine if a numpy masked array contains any non-masked values?
I want to perform a complicated computation on a masked array only if it contains any (or, ideally, at least X) non-masked values. Is there a way to do that efficiently without iterating through the ...
2
votes
1answer
35 views
Filtering of structured array via bit-wise operation (bitmask) on column data
I have a structured array. One column (event_type) is a bitfield. I would like to filter the data via the event_type.
Previously I used filter() but it produces a list that would need to be back ...
0
votes
1answer
50 views
How do you make python read a random value it printed and insert it into an array?
I have written a small coin flipping program for Home work Python, it will choose one of two values; Heads or Tails at random and print them, the loop iterates 10 times then stops. As I understand it ...
6
votes
5answers
90 views
Python: sorting an array with nans
Note: I'm using python and numpy arrays
I tried a bunch of things from over the internet and can't get this simple thing to work for some reason... I have many arrays which each has two columns and a ...
2
votes
1answer
39 views
How to work around the ValueError: array is too big error?
I've got a scipy sparse matrix (csr:Compressed Sparse Row matrix). I'd like to use Orange's feature selection methods (Orange.feature.scoring.score_all (InfoGain/MDL)). However, from my understanding ...
1
vote
2answers
68 views
Python - Print list of objects in a table [duplicate]
I have a class with several attributes:
class Fighter():
def __init__(self, name = "", gender = "", age = 0, weight = 0, win = 0, loss = 0, ko = 0, date = ""):
self.__name = name
...
1
vote
1answer
29 views
Best dtype for creating large arrays with numpy
I am looking to store pixel values from satellite imagery into an array. I've been using
np.empty((image_width, image_length)
and it worked for smaller subsets of an image, but when using it on ...
2
votes
3answers
55 views
Empty an existing NumPy array
Now I have an numpy array X with certain column names, format and length. How can I set all the values to 0 (or empty) in this array, without deleting the format/names etc.?
0
votes
1answer
25 views
Precision loss numpy - mpmath
I use numpy and mpmath in my Python programm. I use numpy, because it allows an easy access to many linear algebra operations. But because numpy's solver for linear equations is not that exact, i use ...
0
votes
4answers
51 views
array coding error in python
I have a set of values
y_train=["User","Bot","User","Bot",.......]
y_pred=["Bot","User","User","Bot".........]
I want to generate an array which returns 1 if the values of y_train[i] and t_pred[i] ...
3
votes
2answers
44 views
Obtain indices corresponding to instances for each type of error in a confusion matrix in numpy
Instead of just obtaining a confusion matrix, I want to be able to get the indices (or array mask) of the instances that committed a specific type of error. So for example, I want to see the instances ...
0
votes
1answer
40 views
Choose random integer between two values in array [duplicate]
I'm making a simple dice-rolling game. I want the player to chose an amount of dices he or she wants to use. With the amount of dices defined I make a calculation to find the range of the dices. Like ...
-1
votes
0answers
60 views
Program interpreting number as array [Python]
I'm trying to create a function representing the velocity of a train first starting at constant velocity and then turning off it's engine at time t = t0. That is
v = lambda t: v0 if t < t1 else ...
0
votes
0answers
29 views
Python multiprocessing on windows with large arrays
I wrote a script on a linux platform using the multiprocessing module of python. When I tried running the program on Windows this was not working directly which I found out is related to the fact how ...
1
vote
1answer
83 views
Swap arrays n times Python
I want to find the minimum f2-f and the correlated E,E2 After n passages.
I have 2 arrays (T,T2) splitted in this way:
split_at = q[:,3].searchsorted([1,random.randrange(LB,UB-I)])
My code below
...
0
votes
1answer
37 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 = ...
0
votes
1answer
35 views
Split array between 2 symbols
I have a really long array from where I want to get some data, but the data I'm interested in is between this signs < and >
I have many of them.
If I wanted them all in a single array, how ...
1
vote
1answer
46 views
SciPy interpolation ValueError: x and y arrays must be equal in length along interpolation axis
I'm trying to work with interp1d of SciPy.interpolate. I "plugged in" two arrays (filtered_mass and integrated_column), of same size, but it still give me ValueError that the sizes of the arrays must ...
0
votes
3answers
67 views
How to add a plus sign before an int in Python?
I need to generate an output in a very specific format, and the positive ints must have a plus sign in front of them. I'm using numpy arrays and was trying stuff like:
if(int(P[pnt])>0):
...
5
votes
1answer
40 views
boolean indexing from a subset of a list in python
I have an array of names, along with a corresponding array of data. From the array of names, there is also a smaller subset of names:
data = np.array([75., 49., 80., 87., 99.])
arr1 = ...
2
votes
2answers
45 views
finding the value of the min and max pixel
I figured out that to find the smallest and largest value for a pixel is
smallest = numpy.amin(image)
biggest = numpy.amax(image)
but this will only work in a grey photo how do i ...
1
vote
3answers
53 views
Division by zero in numpy (sub)arrays
I have three arrays that are processed with a mathematical function to get a final result array. Some of the arrays contain NaNs and some contain 0. However a division by zero logically raise a ...
1
vote
0answers
28 views
Python + OpenCV: Mask image with RGB pixels from another image
I have an RGB video and a single keyframe from that video. In that keyframe, the user will apply a binary mask.
I want to create a mask of the video where pixels have values that exist in the ...
1
vote
1answer
49 views
Avoiding for loops, interpolate over a dimension of a 3D numpy array
I have a large 3D numpy array of dimensions (l, n, m) with elements which correspond to 1D arrays of x, y and z with dimensions l, n and m respectively. I would like to find the elements at given ...
1
vote
1answer
38 views
Trouble accessing column data by name
I have trouble getting a data from a structured numpy array via the column name. At the end is my relevant code. I think it's simple and short enough to be posted in whole (it's a sscce acutally).
...
0
votes
1answer
29 views
How to construct a ndarray from a numpy array? python
I can't seem to convert it into an ndarray in numpy, i've read http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html but it didn't show me how i can convert my input data as shown ...
0
votes
1answer
30 views
What does the array mean in numpy/sklearn datasets? python
From the Naive Bayes tutorial in sklearn there's example on iris dataset but it looks too cryptic, can someone help to enlighten me?
What does the iris.data mean? why is there 4 columns?
What does ...
2
votes
3answers
70 views
Improving performance iterating in 2d numpy array
I have two 2d numpy array (images).
First one defined by image, is storing the sum of a movement at the pixel (i,j)
Second one define by nbCameras, is storing the number of cameras who can see a ...
0
votes
2answers
39 views
Use loop to print an array
Im building a program in which you can enter the tasks you have to do per day.
Now I'm trying to make the program print a list of all the tasks when you're done adding them.
This is the code I have:
...
2
votes
2answers
30 views
Remove Duplicates in two-dimensional array while maintaining sequence
I have found a lot of threads on removing duplicates in arrays but none for my specific use-case. I have a two-dimensional list that I need to remove duplicates from however I must maintain the ...
3
votes
3answers
59 views
An efficient way to calculate the mean of each column or row of non-zero elements
I have a numpy array for ratings given by users on movies. The rating is between 1 and 5, while 0 means that a user does not rate on a movie. I want to calculate the average rating of each movie, and ...
1
vote
2answers
32 views
Simulate an array with “gaps” in Python
What is the standard way to simulate an array in Python? It seems that the list structure only works well when there are no gaps--and you just keep appending values.
But suppose you wanted to make ...
2
votes
3answers
63 views
Finding index of array in 2 multidimensional array in Python
I have an array
v = (x,y,z)
and two multidimensional array
l = (a,b,c),(d,e,f)
and
r = (g,h,i),(l,m,n),(x,y,z).
I want to know the index of v no matter if is in the first or second ...
0
votes
3answers
52 views
Python - Conversion of list of arrays to 2D array
I have a dataset that is formatted like this:
A=[(Num1,Num2,Num3), (Num4,Num5,Num6), (Num7,Num8,Num9)]
with
A.shape = (3,)
and I would like to convert this into a 2D numpy array:
...
0
votes
2answers
62 views
Sort numpy array according to tags
I am a new beginner in python/numpy/scipy. I have a sequence of measured numbers whose values run between 41 and 48 let s say. The sequence is supposed to be periodical and contains values that peaks ...
0
votes
2answers
33 views
Python numpy array
I created numpy array
a = numpy.array([[1,2,3][4,5,6]])
I want to make the array look like this [[1,4],[2,5],[3,6]] and also after I make change I want to return to the original structure.
Is ...
0
votes
1answer
63 views
Fancy indexing with tuples
Say I have a 100x100 array in numpy, from this array I want to select 10 random blocks of (x*x)
pixels and change the values of these blocks simultaneously. What is the best way to index the slices ...
2
votes
4answers
50 views
Calculating cosine values for an array in Python
I have this array named a of 1242 numbers. I need to get the cosine value for all the numbers in Python.
When I use : cos_ra = math.cos(a) I get an error stating:
TypeError: only length-1 arrays ...
0
votes
1answer
36 views
Construct 1 dimensional array from several data files
I'm trying to code a small Python script to do some data analysis. I have several data files, each one being a single column of data, I know how to import each one in python using numpy.loadtxt giving ...
0
votes
2answers
42 views
Python two-dimensional array - changing an element
I have this 7x7 two-dimensional array:
l=[[1, 1, 1, 1, 1, 1, 1],
[1, 0, 2, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 1, ...
1
vote
1answer
29 views
How to add a 2D subarray in an existing 2D array using numpy?
I am having problem to add a subarray to an existing 2D array.
I am actually new to numpy and python and coming from MATLAB this was something trivial to do.
Note that usually a is a big matrix in my ...