2
votes
1answer
27 views

Numpy array, fill empty values

I have an array in numpy, which was generated using np.array() from a python list so my entries are strings, but some of the values are blank. Here is an example array: ['1', '1', '1', '1'] ['1', ...
1
vote
0answers
7 views

Compiling a FORTRAN Module using f2py

I used to compile a FORTRAN program with f2py long time ago. But when I failed to re-compile it today. I guess the reason is not pointing to the right compiler. Last time, my machine was clean only ...
3
votes
2answers
26 views

Determine widening conversion of NumPy types

I have a library based on NumPy with a few classes that overload the arithmetic operations. The internals are a little hairy due to a significant amount of error checking, but I've run across a ...
1
vote
1answer
29 views

Could not locate executable f95, f77, xlf, ifc, g77

I'm trying to install glmnet using these instructions. When I run python setup.py and I choose the interactive option to build, I get the following Could not locate executable XXX errors. I've ...
2
votes
0answers
22 views

Numpy, Virtualenv and the “Cannot find vcvarsall.bat” issue on Windows

I'm trying to install Numpy and other packages into a virtualenv. When I try to install it, I get an error, "cannot find vcvarsall.bat". On my main (system wide) Python, I solved this by ...
4
votes
0answers
52 views

dgemm segfaulting with large F-order matrices in scipy

I'm attempting to compute A*A.T in Python using SciPy's dgemm, but getting a segfault when A has large row dimension (~50,000) and I pass the matrices in in F-order. Of course, the resulting matrix is ...
2
votes
1answer
34 views

product of arrays of different sizes in numpy

I have two arrays, x = np.arange(3) = [0,1,2,3] and y = np.arange(4) = [0,1,2]. Is there a numpy function that gives a table of all of their products ? Or example for times this would be: x*y = ...
0
votes
3answers
51 views

Installing NumPy with pip fails on Ubuntu

When I try: $ sudo pip install numpy on my Ubuntu 12.04 server, I get: ------------------------------------------------------------ /usr/local/bin/pip run on Tue Dec 10 18:25:54 2013 ...
5
votes
0answers
99 views

Why is SciPy acting very differently in IPython and Python?

I wrote this test script: import numpy as np import scipy.linalg n = 130 r = np.array(np.random.normal(size=(n, n)), dtype=np.float32) e = scipy.linalg.eig(r, left=False, right=False) print e.mean() ...
1
vote
1answer
29 views

SciPy optimize.fmin ValueError: zero-size array to reduction operation maximum which has no identity

UPDATE2: A better title (now that I understand the problem) would be: What is the proper syntax for input in scipy optimize.fmin? UPDATE: runnable code was requested, so the function definitions have ...
3
votes
1answer
45 views

Python scipy chisquare returns different values than R chisquare

I am trying to use scipy.stats.chisquare. I have built a toy example: In [1]: import scipy.stats as sps In [2]: import numpy as np In [3]: sps.chisquare(np.array([38,27,23,17,11,4]), np.array([98, ...
1
vote
1answer
51 views

Optimal way for calculating columnwise mutual information using numpy

For a matrix of m x n, what's the optimal (fastest) way to do a Mutual Information calculation for all the columns (n x n ) ? MI = H_of_X + H_of_Y - H_of_XY where H(X) is the Shannon Entropy of X ...
0
votes
2answers
25 views

ndim of structured arrays in numpy?

This is similarly worded question as ndim in numpy array loaded with scipy.io.loadmat? - but it's actually a lot more basic. Say I have this structured array: import sys import numpy as np from ...
0
votes
1answer
34 views

Read filenames from a textfile in python (double backslash issue)

I am trying to read a list of files from a text file. I am using the following code to do that: filelist = input("Please Enter the filelist: ") flist = open (os.path.normpath(filelist),"r") fname = ...
0
votes
1answer
22 views

Keep the fitted parameters when using a cross_val_score in scikits learn

I'm trying to use scikits-learn to fit a linear model using Ridge regression. What I'd like to do is use cross validation to fit many different models, and then look at the parameter coefficients to ...
2
votes
1answer
48 views

“import matplotlib.pyplot as plt” in ipython notebook

I'm new to ipython notebook, but I have the following error message whenever I run import matplotlib.pyplot as plt. I'm using Mac. It works fine with the built-in python or Canopy. The problem only ...
-1
votes
1answer
42 views

Python something resets my random seed

My question is the exact opposite of this one. This is an excerpt from my test file f1 = open('seed1234','r') f2 = open('seed7883','r') s1 = eval(f1.read()) s2 = eval(f2.read()) f1.close() ...
0
votes
1answer
53 views

SystemError: error return without exception set

Whenever I run this code I get the above error, specifically at famList[inc] import numpy as np class Element: def __init__(self, mass, number, ...
3
votes
1answer
45 views

How to force larger steps on scipy.optimize functions?

I have a function compare_images(k, a, b) that compares two 2d-arrays a and b Inside the funcion, I apply a gaussian_filter with sigma=k to a My idea is to estimate how much I must to smooth image a ...
2
votes
1answer
41 views

How to import matrix from excel into numpy and then graph it?

I have a matrix in excel that I am trying to import and convert to a numpy matrix and then graph it with networkx how would I go about doing this? I do have some code but not sure if I am going about ...
0
votes
2answers
25 views

OpenCV detect if image file is colour prior to loading

I know you can use imread to get an image into a numpy array. cv2.imread(path,0) Loads a greyscale image and... cv2.imread(path,1) Loads a colour one. I can call the second one on a greyscale ...
0
votes
2answers
25 views

How do you allow for text qualifiers using numpy genfromtext [duplicate]

I am currently trying to import some comma delimited text data into an array using the numpy library in Python. I am using the following code: data = np.genfromtxt(fname, delimiter=',') I get the ...
3
votes
2answers
59 views

Find index in array to which the sum of all elements is smaller than a limit, quickly

Given is a large array. I am looking for the index up to which all elements in the array add up to a number smaller than limit. I found two ways to do so: import time as tm import numpy as nm # Data ...
1
vote
1answer
27 views

How do I duplicate the values for the last dimension in a numpy array?

I am getting an error in numpy when I perform the pairwise multiplication of two arrays a and b since a has dimensions 100 x 200 x 3, while b has dimensions 100 x 200. However, b contains only 0s and ...
0
votes
1answer
20 views

Trouble importing scipy.stats for scipy 0.13 build 2

I am using Enthought Canopy and recently upgraded both Scipy and numpy to the following: scipy: 0.13 build 2 numpy: 1.8 build 1 When I attempt: from scipy import stats I receive the following ...
4
votes
2answers
73 views

NumPy Matrix Multiplication Efficiency for Matrix With Known Structure

I have two NxN matrices that I want to multiply together: A and B. In NumPy, I used: import numpy as np C = np.dot(A, B) However, I happen to know that for matrix B only row n and column n are ...
0
votes
1answer
24 views

Convert Pandas dataframe to Sparse Numpy Matrix directly

I am creating a matrix from a Pandas dataframe as follows: dense_matrix = numpy.array(df.as_matrix(columns = None), dtype=bool).astype(np.int) And then into a sparse matrix with: sparse_matrix = ...
1
vote
1answer
42 views

ValueError: The elements are 0-sized

Haven't been able to find any information on the web about this problem. I'm trying to read from a text file using numpy. data = ...
1
vote
1answer
24 views

what is the difference between the two datasets for numpy.fft

I am trying to find the period of a sin curve and can find the right periods for sin(t). However for sin(k*t), the frequency shifts. I do not know how it shifts. I can adjust the value of interd below ...
0
votes
2answers
33 views

How can I plot this data?

I am trying to plot this data. I know it should be quite easy to do that but I am struggling (haven't had my coffee yet). h = 1 m = 1 E1 = (((h**2)/(2*m)) * ((((1*np.pi)/2)+((1*np.pi)/2))**2)) E2 = ...
0
votes
2answers
42 views

Python Numpy or Pandas Linear Interpolation For Datetime related Values

I have data that looks like the following but I also have control of how it is formatted. Basically, I want to use Python with Numpy or Pandas to interpolate the dataset to achieve second by second ...
3
votes
1answer
29 views

numpy array to list formatting

How would i format a numpy array of form data1 = np.array([[0,0,0],[0,1,1],[1,0,1],[1,1,0]]) to a list in this format: data = [ [[0,0], [0]], [[0,1], [1]], [[1,0], [1]], ...
0
votes
2answers
30 views

How do you add numpy subarrays to each other?

I have used the numpy.array_split() function in order to split an array of astronomical data into a series of subarrays of known length (the number of subarrays being completely unknown and ...
1
vote
1answer
40 views

Subtracting two interleaved, differently based time-series arrays with numpy?

I have two datasets, a[ts1] and b[ts2], where ts1 and ts2 are timestamps taken at different times (in different bases?). I wanted to plot b[ts2]-a[ts1], but I think I made a mistake, in that the ...
0
votes
2answers
47 views

python, how to write conditions in a function?

How to write conditions in a function (k_over_iq)? dt_for_all_days_np=a numpy array of numbers. def k_over_iq(dt): if dt !=0: return 0.7*(1-e**(-0.01*dt**2.4)) else: ...
2
votes
1answer
44 views

Integral control system does not behave properly

Yesterday I posted a question here: ValueError and odepack.error using integrate.odeint() which I thought had been successfully answered. However I have since noticed a couple of things. When ...
-2
votes
0answers
30 views

Python(numpy) cmputing a 2d array with a 1d array

I have the following arrays: >>> b array([[ 5., 4., 10., 18.], [ 10., 1., 18., 7.], [ 17., 2., 7., 19.]]) >>> z array([2, 4, 6, 7]) I would like ...
0
votes
0answers
44 views

performing arithmetics with several numpy arrays [on hold]

Say I have the arrays below and perform the simple task of adding. a = np.floor(10*random.random((3,4))) b = np.floor(20*random.random((3,4))) >>> a array([[ 2., 5., 2., 2.], ...
0
votes
1answer
29 views

Wrapping C code including Python API using SWIG and distutils fails on Mac 10.8 64bits

I have been trying to wrap an existing C code into a Python module for some time now and I keep running into recurrent errors and a failed build... After an extensive look at the available ...
-1
votes
1answer
16 views

PyQt table Widget Entries to list or numpy array object

i am trying to send some data from a gui i am working on to python. what i want to do ist write a row (gui) to a list (python) or something similar... (directly to a numpy array would be the best)... ...
0
votes
1answer
48 views

Segment Line Intersection algorithm in Numpy

I have two line segments AB: (A1,B1), (A2,B2) and axis_dx coordinate interval. I should find all points crossed by axis coordinates interval i.e.,axis_dx. I already found those points, BUT, the ...
1
vote
1answer
45 views

Build Numpy with Eigen instead of ATLAS or OpenBlas?

since Eigen looks very promising (Benchmark) I wonder if it was possible to compile numpy with the Eigen library, as it is possible to build numpy with ATLAS or with OpenBlas (or with intel-mkl). I ...
2
votes
1answer
65 views

Python: “IndexError: invalid index into a 0-size array”

Obviously, there are loads of threads concerning index errors. But I couldn't find one that helped me out. I use numpy.loadtxt to read in a function f(a,b). a, b, f = np.loadtxt(filename, ...
4
votes
1answer
54 views

Iterator for variable number of nested loops

I'm trying to write an iterator for something like this (simplified from original problem): import numpy as np class IterableNumber: def __init__(self, digits): self.digits = digits ...
4
votes
2answers
450 views

How to obtain a gaussian filter in python

I am using python to create a gaussian filter of size 5x5. I saw this post here where they talk about a similar thing but I didn't find the exact way to get equivalent python code to matlab function ...
2
votes
2answers
10k views

How do I find the length (or dimensions, size) of a numpy matrix in python? [duplicate]

For a numpy matrix in python from numpy import matrix A = matrix([[1,2],[3,4]]) How can I find the length of a row (or column) of this matrix? Equivalently, how can I know the number of rows or ...
2
votes
1answer
2k views

ValueError: object too deep for desired array

""" ___ """ from scipy.optimize import root import numpy as np LENGTH = 3 def process(x): return x[0, 0] + x[0, 1] * 5 def draw(process, length): """ """ X = ...
3
votes
4answers
2k views

How to resample a dataframe with different functions applied to each column?

I have a times series with temperature and radiation in a pandas dataframe. The time resolution is 1 minute in regular steps. import datetime import pandas as pd import numpy as np date_times = ...
83
votes
1answer
31k views

Simple Digit Recognition OCR in OpenCV-Python

I am trying to implement a "Digit Recognition OCR" in OpenCV-Python (cv2). ( It is just for learning purposes ). I would like to learn both KNearest and SVM features in OpenCV. I have 100 ...
11
votes
2answers
7k views

plotting 3d scatter in matplotlib

I have a collection of Nx3 matrices in scipy/numpy and I'd like to make a 3 dimensional scatter of it, where the X and Y axes are determined by the values of first and second columns of the matrix, ...

15 30 50 per page