## 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.

## Python - Divide an Array into Multiple Arrays Dependent on Array Values

I have a list which needs to be split into multiple lists of differing size. The values in the original list randomly increase in size until the split point, where the value drops before continuing to increase. The values must remain in order after b

## 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

## Counting overlapping values ​​of two 2D numpy binary tables for a specific value

I start with two images of the same size. I convert them to binary black/white numpy arrays (0 = black 1 = white). I'd like to find how many of the black pixels overlap (0 value at same position in both arrays). I know how to do this with for loops,

## Slice a Python list with a NumPy array of indices & mdash; anyway fast?

I have a regular list called a, and a NumPy array of indices b. (No, it is not possible for me to convert a to a NumPy array.) Is there any way for me to the same effect as "a[b]" efficiently? To be clear, this implies that I don't want to extra

## 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, c.columns.name = 'col' I get this, col 0 1 2 3 4 5 col 0 1.000000 0.051975 -0.171113 0.196975 0.057700 -0.

## numty array dtype arrives as default int32 in a Windows 10 64 bit machine

I have installed Anaconda 3 64 bit on my laptop and written the following code in Spyder: import numpy.distutils.system_info as sysinfo import numpy as np import platform sysinfo.platform_bits platform.architecture() my_array = np.array([0,1,2,3]) my

## Reshape the table on xAxis and fill with the average value in Python?

i'm trying to reshape a array in Python and fill it with mean values. Example: Given array: [2, 3, -20, 10, 4] Searched array: [2, 2.5, 3, -8.5, -20, -5, 10, 7, 4] More advanced: I've got an array with e.g 1000 samples. But I know it should be 1300 s

## Fast linear interpolation in Numpy / Scipy & ldquo; along a path & rdquo;

Let's say that I have data from weather stations at 3 (known) altitudes on a mountain. Specifically, each station records a temperature measurement at its location every minute. I have two kinds of interpolation I'd like to perform. And I'd like to b

## 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

## How to assign the scipy.sparse matrix to the NumPy table via indexing?

When I try to assign a scipy.sparse matrix s (any of the available sparse types) to a NumPy array a like this: a[:] = s I get a TypeError: TypeError: float() argument must be a string or a number Is there a way to get around this? I know about the to

## 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

## Find the closest float in the table for all floats in another table

I have a performance issue while "filtering" an array according to the closest float found in another array. This is a MWE of the problem: import numpy as np def random_data(N): # Generate some random data. return np.random.uniform(0., 10., N).t

## NumPy: Vectorizes Finding the Closest Value in an Array for Each Element in Another Array

Input known_array : numpy array; consisting of scalar values only; shape: (m, 1) test_array : numpy array; consisting of scalar values only; shape: (n, 1) Output indices : numpy array; shape: (n, 1); For each value in test_array finds the index of th

## Replace & ldquo; zero-columns & rdquo; with values ​​from a numpy array

Ok it´s late and i cannot solve the easiest problems anymore: I have a Matrix with "zero-columns", these columns should be replaced with a value from another array (same column index) that has the same number of columns: a=np.array([[2,0,0,0],[1

## 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

## choose elements based on the complement of records in Python pandas

I have a python pandas DataFrame question. There are two DataFrames containing records, df1 and df2. They contain the following values: df1: pkid start end 0 0 2005 2005 1 1 2006 2006 2 2 2007 2007 3 3 2008 2008 4 4 2009 2009 df2: pkid start end 0 3

## How to convert a Numpy 2D array with a dtype object into a regular 2D float array

As part of broader program I am working on, I ended up with object arrays with strings, 3D coordinates and etc all mixed. I know object arrays might not be very favorite in comparison to structured arrays but I am hoping to get around this without ch

## 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 : import numpy as np In : from scipy.special import erfcinv In : 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 = -a

## 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

## The fastest way to convert a Numpy table into a sparse dictionary?

I'm interested in converting a numpy array into a sparse dictionary as quickly as possible. Let me elaborate: Given the array: numpy.array([12,0,0,0,3,0,0,1]) I wish to produce the dictionary: {0:12, 4:3, 7:1} As you can see, we are simply converting