1
vote
1answer
16 views

OpenCV TypeError: contour is not a numpy array, neither a scalar

I'm trying to use OpenCV to extract tags from Nike images. This is a tutorial code taken from: http://opencv-code.com/tutorials/ocr-ing-nikes-new-rsvp-program/ I've modified few lines of code though ...
6
votes
2answers
31 views

perform varimax rotation in python using numpy

I am working on principal component analysis of a matrix. I have already found the component matrix shown below A = np.array([[-0.73465832 -0.24819766 -0.32045055] [-0.3728976 ...
2
votes
1answer
30 views

Exclude enpoints in uniform mesh

I would like to create a uniform 1D mesh with N points over an interval of reals (0, pi). Currently I have the following working code: import numpy as np u = np.linspace(0, np.pi, N+1, endpoint = ...
5
votes
2answers
75 views

Non-trivial sums of outer products without temporaries in numpy

The actual problem I wish to solve is, given a set of N unit vectors and another set of M vectors calculate for each of the unit vectors the average of the absolute value of the dot product of it with ...
3
votes
1answer
36 views

NaNs in pandas.DataFrame not printing to Excel

I have a pandas.DataFrame which contains numpy.nan floats. When using the Excel writer however, the fields where there should be numpy.nan floats are blank. I would expected at least a string ...
3
votes
3answers
83 views

Python Sigma Sums

I have a list of values x=[1,-1,-1,1,1,-1,1,-1,1,-1] and I have another blank list y=[ ] I am trying to create a function that will take a sigma sum of values in x and store them in y. For ...
0
votes
2answers
28 views

numpy's loadtxt gives error converting to int when string contains decimal

I'm having trouble trying to load a txt file into a structured array. Here's a simple example showing the problem. This works fine: import numpy as np from StringIO import StringIO in1 = ...
0
votes
2answers
41 views

Find all the missing directed edges in an adjacency matrix

I use a numpy matrix to represent a directed graph, like this: 0 0 0 1 0 1 1 0 0 Given such a matrix, I want to find all the missing directed edges for which there exists a directed edge in ...
4
votes
1answer
34 views

Read a 3d Array from File

Lets say I have a file with the following values: 1 2 3 4 11 12 13 14 and I want to read them as a numpy 2x2x2 array. The standard command np.loadtxt('testfile') reads them in as lots of vectors ...
2
votes
1answer
42 views

Taking up too much memory - python

I wrote a recursive function that exhaustively generates matrices of certain characteristics. The function is as such: def heavies(rowSums,colSums,colIndex,matH): if colIndex == len(colSums) - 1: ...
1
vote
1answer
33 views

Polynomial fitting problems in numpy

I was trying to implement a standard polynomial fitting program, and came across a problem that I could not understand. Here is the code where I have a sample x and y data, which I fit using the ...
1
vote
0answers
56 views

Generate any random number from a CDF in python

I have a piece of python code that is suppose to generate a random number from a CDF distribution, but the random numbers it produces are only 8 different values. I am wanting any value with in the ...
2
votes
1answer
56 views

Can numpy einsum() perform outer addition?

In numpy, we can perform "outer addition" between two vectors a and b like this: a=np.c_[1,2,3] b=np.c_[4,5,6] result=a+b.T # alternatively this can be a.T+b Is it possible to use einsum to make ...
3
votes
2answers
41 views

numpy.nan weird behaviour in hashed object

I am experiencing a weird behaviour when using numpy.nan that I can't understand. Here is a minimal example: from numpy import nan def _bool3key(x): """ Defines the keys used to order the list. ...
2
votes
1answer
34 views

Reduce Two Pandas Series to a Single One

Problem: I'd like to take Series 1 and Series 2 and create a new Series with values (series 1, Series 2). Essentially, I have two pandas series that I would like to combine into one. Although the ...
1
vote
1answer
19 views

Using df.apply() with a Pandas MuliIndex / carrying out operations on hierarchical index rows?

Question What is an efficient way to carry out numerical operations to hierarchical index rows? Problem I have a large dataframe, over 1gb, that is indexed by year and then by country code. A ...
3
votes
1answer
53 views

Gaussian Smoothing an image in python

I am very new to programming in python, and im still trying to figure everything out, but I have a problem trying to gaussian smooth or convolve an image. This is probably an easy fix, but I've spent ...
1
vote
0answers
67 views

Python float types vs Decimal

I am an intern at TCD, Physics. I wrote a code to perform some data analysis on random particle packings. The code is written in Python. The code reads in columns of data from a .txt file, provided ...
2
votes
1answer
42 views

Modify numpy array column by column inside a loop

Is there a way to modify a numpy array inside a loop column by column? I expect this could be done by some code like that: import numpy as n cnA=n.array([[10,20]]).T mnX=n.array([[1,2],[3,4]]) for ...
0
votes
1answer
28 views

Matplotlib fill blank image line by line, when I receive data from socket

I have data coming from a socket. I want in the beginning to create an empty image, then update this image every time I receive the data from the socket. The problem is when I receive a huge amount of ...
3
votes
1answer
50 views

Please clarify the following Python numpy array initialization and splicing examples

I am using Python version 2.6 and learning numpy version 1.3. I have tried out several numpy array initialization and column splicing examples below, and added some inline questions as comments and a ...
1
vote
1answer
55 views

Kurtosis,Skewness of a bar graph? - Python

What is an efficient method for determining the skew/kurtosis of a bar graph in python? Considering that bar graphs are not binned (unlike histograms) this question would not make a lot of sense but ...
0
votes
1answer
22 views

Port Python virtualenv to another system

I am using many python packages like numpy, bottleneck, h5py, ... for my daily work on my computer. Since I am root on this machine it is no problem to install these packages. However I would like to ...
2
votes
2answers
47 views

Vectorizing operation in NumPy

Is there a general way to vectorize these kind of operations in NumPy? In [2]: N = 8 In [3]: ll = np.arange(8) In [4]: arr = np.zeros(ll.shape + (2, 2)) In [5]: ll.shape Out[5]: (8,) In [6]: ...
1
vote
1answer
17 views

apply fromiter over matrix

Why does fromiter fail if I want to apply a function over the entire matrix? >>> aaa = np.matrix([[2],[23]]) >>> np.fromiter( [x/2 for x in aaa], np.float) array([ 1., 11.]) ...
2
votes
2answers
94 views

Improving Numpy speed for Gauss-Seidel (Jacobi) Solver

This question is a follow-up to a recent question posted regarding MATLAB being twice as fast as Numpy. I currently have a Gauss-Seidel solver implemented in both MATLAB and Numpy which acts on a 2D ...
2
votes
2answers
37 views

Expanding NumPy array over extra dimension

What is the easiest way to expand a given NumPy array over an extra dimension? For example, suppose I have >>> np.arange(4) array([0, 1, 2, 3]) >>> _.shape (4,) >>> ...
2
votes
2answers
31 views

Numpy randint appending

So im generating a random list with numpy named heights... heights = random.randint(10, size=random.randint(20)) Im using this list for testing purposes, but I have one condition, I need to append ...
1
vote
1answer
41 views

Pass percentiles to pandas agg function

I want to pass the numpy percentile() function through pandas' agg() function as I do below with various other numpy statistics functions. Right now I have a dataframe that looks like this: ...
2
votes
2answers
43 views

Numpy, python: automatically expand dimensions of arrays when broadcasting

Consider the following exercise in Numpy array broadcasting. import numpy as np v = np.array([[1.0, 2.0]]).T # column array A2 = np.random.randn(2,10) # 2D array A3 = np.random.randn(2,10,10) # 3D ...

1 2 3 4 5 192
15 30 50 per page