How to remove items from a list by index

I am a python beginner. The data I am given in a text file(.txt) that contains my x and y values. x and y values are tab separated. (x values) (y values) 113 0 116 2 119 0 214 3 220 0 230 3 290 5 My task is to remove x and y values when y value is 0.

Numpy sampling function

Is there any function in numpy or scipy that for a given pdf, a point sampled from that distribution will be returned? For example, I have a mixture of Gaussian distribution: means = 0., 8. stdevs = 1.0,1.0 weights = 0.75,0.25 pdfs = [p * norm.pdf(x,

How to write two variables in one line?

This question already has an answer here: Print multiple arguments in python 10 answers Python: How to write multiple strings in one line? 4 answers I would like to write two variable in a file. I mean this is my code : file.write("a = %g\n" %(p

pandas corr table column name behavior

I'm calculating a corr table in pandas, df = pd.DataFrame(np.random.rand(6, 6)) c = df.corr() But when I try to change the name of the columns, = 'col' I get this, col 0 1 2 3 4 5 col 0 1.000000 0.051975 -0.171113 0.196975 0.057700 -0.

Compare two lists / tuples (nested) of NumPy tables

Let us say I have two nested structures of the following kind: [(array, (array, array, array)), (array, (array, array, array))] All of the interesting data inside are NumPy arrays. What is the easiest way to compare two of such data structures? I cou

Delete rows at selected indexes from a numpy array

In my dataset I've close to 200 rows but for a minimal working e.g., let's assume the following array: arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16], [17,18,19,20], [21,22,23,24]]) I can take a random sampling of 3 of the rows as

Transform NumPy array of characters into a string

I have a numpy array of characters and when I write it to file it writes as: ['K' 'R' 'K' 'P' 'T' 'T' 'K' 'T' 'K' 'R' 'G' 'L'] I want it to write with just the letters and without the brackets or quotations i.e. as: KRKPTTKTKRGL I have looked at nump

Remove outliers in each column (and the corresponding line)

My Numpy array contains 10 columns and around 2 million rows. Now I need to analyze each column separately, find values which are outliers; and delete the entire corresponding row from the array. So I'd start analyzing column 0; find outliers at Row

Randomly choose all items in the list once

How is it possible to randomly choose a number from a list with n elements, n time without picking the same element of the list twice. I wrote a code to choose the sequence number of the elements in the list but it is slow: >>>redshift=np.array([

numpy array assignment using clipping

If b is a 2x2 np.ndarray and the following assignment is performed, what does numpy do in the background, i.e. does it convert the list[100, 100] first to a numpy array or does it directly use the list[100,100] to fill in the values in the first row

Numpy meshgrid function

I have a problem where I want to plot the determinant of a matrix as a function of parameters, so I have a script def f(x, y): DD = np.matrix([[0., 0.],[0., 0.]]) + 0.j omega = x + 1.j * y # set up dispersion matrix DD[0,0] = 1 + omega DD[1,0] = omeg

pip fails to install numpy error code 1

I'm trying to install numpy using pip. When I type pip install numpy in the command prompt it goes to work but won't install the file and returns an error code 1. I am using windows 8 64-Bit and python 2.7.This is the final bit of the error message C

Scipy erfcinv explodes unexpectedly near 1e-16

I've been using scipy.special.erfcinv to calculate Z scores from pvalues. However, when the pvalues become very small, erfcinv gets unexpectedly large. Any ideas? Example: In [1]: import numpy as np In [2]: from scipy.special import erfcinv In [3]: e

Tracing of periodic trajectories

I have some data of a particle moving in a corridor with closed boundary conditions. Plotting the trajectory leads to a zig-zag-trajectory. I would like to know how to hinder plot() from connecting the points, where the particle comes back to the sta

Use a numpy array in shared memory for multiprocessing

I would like to use a numpy array in shared memory for use with the multiprocessing module. The difficulty is using it like a numpy array, and not just as a ctypes array. from multiprocessing import Process, Array import scipy def f(a): a[0] = -a[0]

From for loops to numpy point implementation

N=100 reliab=zeros((N,N)) for i in range(N): for j in range(N): if random() < 0.6: reliab[i,j] = 1 else: reliab[i,j] = 0 As in my code this matrix filling is recalled a huge number of times, these for loops should be changed with a dot product...but

reduce the time for a long python loop

a other stupid question from my side ;) I have some issues with the following snippet with len(x)=len(y)=7'700'000: from numpy import * for k in range(len(x)): if x[k] == xmax: xind = -1 else: xind = int(floor((x[k]-xmin)/xdelta)) if y[k] == ymax: yi