numpy

Calculating e with high precision with python?

Is it possible to calculate the number e with high precision (2000+ decimal places) with Python? (I was thinking with Numpy or SciPy) ...

Is it possible in numpy to use advanced list slicing and still get a view?

In other words, I want to do something like A[[-1, 0, 1], [2, 3, 4]] += np.ones((3, 3)) instead of A[-1:3, 2:5] += np.ones((1, 3)) A[0:2, 2:5] += np.ones((2, 3)) ...

Installing Python modules on OSX using easy_install or setup.py install

I am running Snow Leapord 10.6 and trying to install the following python modules: 1) numpy 2) scipy 3) matplotlib I am running into problems because OSX contains two version of Python: 1) /Library/Python/ 2) /System/Library/Frameworks/Python.framework/ It appears that when I execute the following command: sudo easy_install -U {modu...

Python: shape of a matrix and imshow()

Hello! I have a 3-D array ar. print shape(ar) # --> (81, 81, 256) I want to plot this array. fig = plt.figure() ax1 = fig.add_subplot(111) for i in arange(256): im1 = ax1.imshow(ar[:][:][i]) plt.draw() print i I get this error-message: im1 = ax1.imshow(ar[:][:][i]) IndexError: list index out of range Why do I g...

Python/Numpy error: NULL result without error in PyObject_Call

I've never seen this error before, and none of the hits on Google seem to apply. I've got a very large NumPy array that holds Boolean values. When I try writing the array using numpy.dump(), I get the following error: SystemError: NULL result without error in PyObject_Call The array is initialized with all False values, and the only ti...

Matrix multiplication with Numpy

Hi all, Assume that I have an affinity matrix A and a diagonal matrix D. How can I compute the Laplacian matrix in Python with nympy? L = D^(-1/2) A D^(1/2) Currently, I use L = D**(-1/2) * A * D**(1/2). Is this a right way? Thank you. ...

How to call an element in an numpy array?

This is a really simple question, but I didnt find the answer. How to call an element in an numpy array? import numpy as np arr = np.array([[1,2,3,4,5],[6,7,8,9,10]]) print arr(1,1) The code above doesnt work. ...

Python: Error --> setting an array element with a sequence

The data-element is a float-number and no sequence (I think). But I get the error "setting an array element with a sequence". folder = r"C:\Dokumente und Einstellungen\ssc" contents=os.listdir(folder) ar = zeros((81,81,256),int) filenumber = 0 for d in contents: if str(".bin") in d: filename = os.path.join("C:\\Dokumente u...

Python: get the position of the biggest item in an numpy array

How can I get get the position of the biggest item in an numpy array? ...

How to filter a numpy.ndarray by date?

I have a 2d numpy.array, where the first column contains datetime.datetime objects, and the second column integers: A = array([[2002-03-14 19:57:38, 197], [2002-03-17 16:31:33, 237], [2002-03-17 16:47:18, 238], [2002-03-17 18:29:31, 239], [2002-03-17 20:10:11, 240], [2002-03-18 16:18:08, 252], [...

Running multiple instances of a python program efficiently & economically?

I wrote a program that calls a function with the following prototype: def Process(n): # the function uses data that is stored as binary files on the hard drive and # -- based on the value of 'n' -- scans it using functions from numpy & cython. # the function creates new binary files and saves the results of the scan in...

Cumulative summation of a numpy array by index

Assume you have an array of values that will need to be summed together d = [1,1,1,1,1] and a second array specifying which elements need to be summed together i = [0,0,1,2,2] The result will be stored in a new array of size max(i)+1. So for example i=[0,0,0,0,0] would be equivalent to summing all the elements of d and storing the ...

numpy.isnan returns TypeError

I do: print "e: ", scaled_target, type(scaled_target) print "f: ", numpy.isnan(scaled_target) which returns e: [0.0 0.0 0.0 0.0] <type 'numpy.ndarray'> f: Traceback (most recent call last): File "./a.py", line 106, in <module> print "f: ", numpy.isnan(scaled_target) TypeError: function not supported for these types, and can't...

Create a new array from numpy array based on the conditions from a list

Suppose that I have an array defined by: data = np.array([('a1v1', 'a2v1', 'a3v1', 'a4v1', 'a5v1'), ('a1v1', 'a2v1', 'a3v1', 'a4v2', 'a5v1'), ('a1v3', 'a2v1', 'a3v1', 'a4v1', 'a5v2'), ('a1v2', 'a2v2', 'a3v1', 'a4v1', 'a5v2'), ('a1v2', 'a2v3', 'a3v2', 'a4v1', 'a5v2'), ('a1v2', 'a2v3', 'a3v2', 'a4v2', 'a...

How to create the histogram of an array with masked values, in Numpy?

In Numpy 1.4.1, what is the simplest or most efficient way of calculating the histogram of a masked array? numpy.histogram and pyplot.hist do count the masked elements, by default! The only simple solution I can think of right now involves creating a new array with the non-masked value: histogram(m_arr[~m_arr.mask]) This is not very...

Parallelize resolution of differential equation in Python

hi, i am solving a system of ordinary differential equations using the odeint function. Is it possible (and if yes how) to parallelize easily this kind of problem? ...

Converting a 2D numpy array to a structured array

I'm trying to convert a two-dimensional array into a structured array with named fields. I want each row in the 2D array to be a new record in the structured array. Unfortunately, nothing I've tried is working the way I expect. I'm starting with: >>> myarray = numpy.array([("Hello",2.5,3),("World",3.6,2)]) >>> print myarray [['Hello' '...

Read flat list into multidimensional array/matrix in python

I have a list of numbers that represent the flattened output of a matrix or array produced by another program, I know the dimensions of the original array and want to read the numbers back into either a list of lists or a NumPy matrix. There could be more than 2 dimensions in the original array. e.g. data = [0, 2, 7, 6, 3, 1, 4, 5] sha...

Are numpy's math functions faster than python's?

hi, i have a function defined by a combination of basic math functions (abs, cosh, sinh, exp ...) I was wondering if it makes a difference (in speed) to use, for example: numpy.abs() instead of abs()? ...

Numpy broadcast array

Hi, I have the following array in NumPy: A = array([1, 2, 3]) How can I obtain the following matrices (without an explicit loop)? B = [ 1 1 1 2 2 2 3 3 3 ] C = [ 1 2 3 1 2 3 1 2 3 ] Thanks! ...