numpy

Using genfromtxt to import csv data with missing values in numpy

Hi, I have a csv file that looks something like this (actual file has many more columns and rows): 1,2,3,4,5 6,7,8,9,10 11,12,13,14,15 16 Say the name of the file is info.csv If I try to import this using data = numpy.genfromtxt('info.csv', delimiter = ',') then I get the following error: ValueError: Some errors were detected ! ...

Occasional ctypes error importing numpy from mod_wsgi django app

Here's the setup: Django (1.2) app on mod_wsgi that imports ctypes Python 2.6.5 Apache 2.2.3 SELinux disabled RedHat EL 5 64bit some of the file system is mounted over nfs Occasionally, when I restart apache I get an import error when it's trying to import ctypes. Every incoming request fails with a 500 error. If I restart apache usu...

Python Warning, possibly Numpy

As I run my code I get these warnings, allways in groups of four, sporadicly. I have tried to locate the source by placing debug messages before and after sertain statements to pin-point its origin. Warning: invalid value encountered in double_scalars Warning: invalid value encountered in double_scalars Warning: invalid value encountere...

Organizing and building a numpy array for a dynamic equation input

I'm not sure if my post question makes lots of sense; however, I'm building an input array for a class/function that takes in a lot of user inputed data and outputs a numpy array. # I'm trying to build an input array that should include following information: ''' * zone_id - id from db - int * model size - int * type of analysis - o...

Fourier space filtering

I have a real vector time series x of length T and a filter h of length t << T. h is a filter in fourier space, real and symmetric. It is approximately 1/f. I would like to filter x with h to get y. Suppose t == T and FFT's of length T could fit into memory (neither of which are true). To get my filtered x in python, I would do: impor...

counting non-zero elements within each row and within each column of a 2D numpy array

I have a numpy matrix that contains mostly nonzero values, but that occasionally will contain a zero value. I need to be able to: 1.) count the non-zero values in each row, and put that count into a variable that I can use in subsequent operations, perhaps by iterating through row indices and performing the calculations during the itera...

image information along a polar coordinate system

Hi, I have a set of png images that I would like to process with Python and associated tools. Each image represents a physical object with known dimensions. In each image there is a specific feature of the object at a certain pixel/physical location. The location is different for each image. I would like to impose a polar coordinate s...

Optimizing mean in python

I have a function which updates the centroid (mean) in a K-means algoritm. I ran a profiler and noticed that this function uses a lot of computing time. It looks like: def updateCentroid(self, label): X=[]; Y=[] for point in self.clusters[label].points: X.append(point.x) Y.append(point.y) self.clusters[label...

Subsetting data in python

Hi, I want to use the equivalent of the subset command in R for some python code I am writing. Here is my data: col1 col2 col3 col4 col5 100002 2006 1.1 0.01 6352 100002 2006 1.2 0.84 304518 100002 2006 2 1.52 148219 100002 2007 1.1 0.01 6292 10002 2006 1.1 0.01 5968 10002 2006 1....

numpy matrix multiplication

I am trying to figure out how to do a kind of scalar matrix multiplication in numpy. I have a = array(((1,2,3),(4,5,6))) b = array((11,12)) and i want to do a op b to result in array(((1*11,2*11,3*11),(4*12,5*12,6*12)) right now I am using the following expression c= a * array((b, b, b)).transpose() It seems like there must...

in numpy what is the multi dimensional equivalent of take

I have this bit of code def build_tree_base(blocks, x, y, z): indicies = [ (x ,z ,y ), (x ,z+1,y ), (x ,z ,y+1), (x ,z+1,y+1), (x+1,z ,y ), (x+1,z+1,y ), (x+1,z ,y+1), (x+1,z+1,y+1), ] children = [blocks[i] for i in indicies] return Node(children=...

Numpy/Python performing terribly vs. Matlab

Novice programmer here. I'm writing a program that analyzes the relative spatial locations of points (cells). The program gets boundaries and cell type off an array with the x coordinate in column 1, y coordinate in column 2, and cell type in column 3. It then checks each cell for cell type and appropriate distance from the bounds. I...

ATLAS Linear algebra and openmpi on multicore with python

I use mpi4py and openmpi on a multi-cpu/core machine to do linear algebra. My numpy is built using ATLAS. Suppose I have a 4 core machine and I would like to run a 4 node python script that does linear algebra on each node using numpy. How can I ensure that ATLAS does not use more than one core when it is doing linear algebra in each no...

how to do scatter/gather operations in numpy

lets say i have arrays: a = array((1,2,3,4,5)) indices = array((1,1,1,1)) and i perform operation: a[indices] += 1 the result is array([1, 3, 3, 4, 5]) in other words, the duplicates in indices are ignored if I wanted the duplicates not to be ignored, resulting in: array([1, 6, 3, 4, 5]) how would I go about this? the examp...

using file/db as the buffer for very big numpy array to yeild data prevent overflow?

Dear All, In using the numpy.darray, I met a memory overflow problem due to the size of data,for example: Suppose I have a 100000000 * 100000000 * 100000000 float64 array data source, when I want to read data and process it in memory with np. It will raise a Memoray Error because it works out all memory for storing such a big array in ...

Python: numpy and matplotlib anomaly

This is the first time I am using matplotlib and numpy. Here goes the problem: If I goto python cli, the intended code works fine. Here is that code >>> from numpy import * >>> y = array([1,2]) >>> y = append(y, y[len(y) - 1]+1) >>> y array([1, 2, 3]) But if I use it with matplotlib in a script I get this error. line 26, in onkeypr...

Numpy csv script gives 'ValueError: setting an array element with a sequence'

I have a python script that successfully loads a csv file into a 2d numpy array and which then successfully extracts the value of a desired cell based on its column and row header values. For diagnostic purposes, I have the script print the contents of the data matrix before it is put into a numpy array. The script works when the data ...

Efficiently detect sign-changes in python

I want to do exactly what this guy did: Python - count sign changes However I need to optimize it to run super fast. In brief I want to take a time series and tell every time it crosses crosses zero (changes sign). I want to record the time in between zero crossings. Since this is real data (32 bit float) I doubt I'll every have a numb...

Indexing with Masked Arrays in numpy

I have a bit of code that attempts to find the contents of an array at indices specified by another, that may specify indices that are out of range of the former array. input = np.arange(0, 5) indices = np.array([0, 1, 2, 99]) What I want to do is this: print input[indices] and get [0 1 2] But this yields an exception (as exp...

Numpy Routine for Computing Matrix Minors?

Hi, I'm interested in using numpy to compute all of the minors of a given square matrix. Is there a slick way of using array slicing to do this? I'm imagining that one can rotate the columns, delete the last column, rotate the rows of the resulting matrix and delete the last row, but I haven't found anything in the numpy documentation...