Tagged Questions
0
votes
3answers
18 views
How to remove duplicates from a list of tuples but keeping the original order
I want to remove redundant tuples but preserve the order of appearance. I looked at similar questions. This question Find unique rows in numpy.array looked very promising but somehow it did not work ...
1
vote
1answer
9 views
Vectorized way of accessing row specific elements in a numpy array
I have a 2-D NumPy array and a set of indices the size of which is the first dimension of the NumPy array.
X = np.random.rand(5, 3)
a = np.random.randint(0, 3, 5)
I need to do something like
for ...
1
vote
2answers
27 views
Optimal way to append to numpy array
I have a numpy array and I can simply append an item to it using append, like this:
numpy.append(myarray, 1)
In this case I just appended the integer 1.
But is this the quickest way to append to ...
3
votes
1answer
19 views
Exponential Decay on Python Pandas DataFrame
I'm trying to efficiently compute a running sum, with exponential decay, of each column of a Pandas DataFrame. The DataFrame contains a daily score for each country in the world. The DataFrame looks ...
0
votes
1answer
24 views
LASSO regression result different in Matlab and Python
I am now trying to learn the ADMM algorithm (Boyd 2010) for LASSO regression.
I found out a very good example on this page.
The matlab code is shown here.
I tried to convert it into python language ...
-1
votes
0answers
19 views
Multivariate analysis toolbox in Python
I'm a Matlab user but I have to do a data analysis (exploratory statistics, data mining, multivariate analysis...) workshop for some students using Python (free, and we already have scripts in python ...
0
votes
0answers
28 views
Plot 4d dimensional
I have a 4d or higher ellipsoid in matrix form (which form is important). I wish to plot 3d dimensional plots (The projection on 3d hyperplane). Of the 4/5/6 dimensions I am projecting from, I want to ...
0
votes
0answers
27 views
Why is axis==0 columns when computing std, but axis==1 columns when deleting?
As you can see in the example code below (with print results as comments), to find the std of columns I need to set the axis to 0, but to remove columns I need to set the axis to 1. What gives?
...
0
votes
1answer
33 views
Creating 3-D Numpy array with parameters
So I need to write code that accomplishes the following:
Write a Python code that produces a variable op_table that is a numpy array with three
axes, i, j, and k. Define three ...
0
votes
1answer
13 views
AttributeError: function' object has no attribute 'linreg'
I am new to python and programming and am working my way through "Machine Learning: An Algorithmic Perspective." I was told to normalise data, seperate it into training and testing data, recover the ...
0
votes
0answers
13 views
How to add different arrays from the center point of an array in Python/NumPy
following on from " Adding different sized/shaped displaced NumPy matrices ", I want to extend the code, so that I can do the addition at the center
import numpy as np
#two 3d arrays, of different ...
2
votes
2answers
41 views
How to select a specific columns in a text file by the specific column names and extract their contents in Python
I am a beginner in Python and I am finding it very difficult to come up with the correct solution for this problem. I glanced through all the similar posts in stackoverflow and couldn't find the ...
1
vote
3answers
22 views
Substitute entries in a large numpy tensor with dictionary values
I have a huge numpy tensor and I have a huge dictionary, what is the fastest way of substituting the entries in the tensor(assuming they are the keys) with those with the corresponding values in ...
1
vote
1answer
9 views
How to find the central point of a region segmented by watershed?
I'm working with watershed algorithm in scikit (skimage) to segmentate my image and then I detect the segmented objects by using function find_objects from ndimage library. The returned type is a ...
0
votes
0answers
13 views
GCC-PHAT cross correlation in Python
I am trying to implement GCC-PHAT in python.
The approach is similar to the following two links:
link1 and link2
It seems the only difference between GCC-PHAT and normal cross-correlation using FFT ...
0
votes
1answer
23 views
Python finding time to return to equilibrium in SHM
I have a model y which models the motion of simple harmonic motion (SHM) of say, a pendulum. I want to be able to find the time t in which the pendulum returns to its rest position (at y=d) after it ...
0
votes
0answers
29 views
Average array by intervals
I have a 2D array of floats which looks like this (data here):
As you can see, the values are not unique and a single x value can have several y values.
I'd like to produce a single average curve ...
-1
votes
3answers
18 views
Python Remove Column from Numpy Array based on some Condition
The Title says it all.
Suppose I have a numpy array containing values summing up to 1.
[0.5 0.3 0.1 0.05 0.03 0.01]
And I would want to remove all Values of the array which are smaller than ...
1
vote
1answer
29 views
Computing an array of values for each meshgrid point
I have a function that depends on some parameters and which output is an array. For example:
def my_func(xs,param1,param2,param3):
values = xs**param1 + xs*param2**2 + param3*xs
return values
...
1
vote
1answer
39 views
How can a numpy array be created on a laptop when it's size exceeds system memory?
I have an 8gb Macbook Pro and if I create a numpy array like so, it tells me that it is 2Terabytes in size? I'm confused by this because I thought a numpy array allocated contiguous RAM. So how does ...
0
votes
0answers
17 views
how to handle different data type in sklearn
I have a Pandas.DataFrame object dfTrain which stores all the training data point
There are multiple data types in this dataframe, e.g., a column named "IP" stores string values(like "168.0.0.1"), ...
-4
votes
0answers
29 views
UsingPython 2.6 I have to reformat ascii [on hold]
I've loaded my ascii text file into a numpy array, essentially they are co-ordinates X,Y, ID something like this:
6949.532 40268.731 1
2518.221 35904.057 1
5759.599 29825.878 1
...
0
votes
2answers
17 views
Comparision of numpy module array with list
I am trying to compare numpy array with list....
Because i am new to python, i don't know about numpy array
I want to know the application of numpy array
Please help out in understanding numpy array.
...
0
votes
1answer
27 views
Python increase specific matrix elements
I want to identify certain elements in a matrix (which are say, smaller than 4) and increase the element by 1000. e.g. an element is 2, so this element is changed to 1002. How can I do this ...
1
vote
2answers
28 views
How to import csv file as numpy.array in python?
say i have a csv file.csv in this format:
dfaefew,432,1
vzcxvvz,300,1
ewrwefd,432,0
how to import the second column as a numpy.array and the third column as another one like this:
second = ...
1
vote
2answers
40 views
How do you pass a numpy array to openCV without saving the file as a png or jpeg first?
I am trying to take a screenshot, then convert it to a numpy array. I then want to run cv2.matchTemplate using the screenshot. So far the only way I have gotten this to work is to save the image: ...
0
votes
0answers
27 views
Easiest way to convert date columns in pandas DataFrame to pandas datetime [duplicate]
I have a data organized on columns as a pandas DataFrame, for example:
import numpy as np
import pandas as pd
yy = np.arange(2000,2005)
mm = np.array([1,1,1,1,1])
dd = np.array([3,14,2,6,20])
date ...
-1
votes
1answer
16 views
Incorrect behaviour or numpy.argmax function (closed, my fail here)
I have a numpy array of length 500, and try to get the position of its largest element.
> type(arr)
<type 'numpy.ndarray'>
> numpy.max(arr)
0.99841506 # the largest value is here the last ...
0
votes
1answer
28 views
Efficient calculation on complete columns (pytables, hdf5, numpy)
I have a simple HDF5 file (created by PyTables) with ten columns and 100000 rows. For every value I have to apply a simple linear equation, with different parameters per column and write the stuff to ...
-2
votes
1answer
39 views
Index of element in Numpy array 1
I am doing work on parallelization .and I have numpy array in between.
I want to check the index of numpy array
for example :
pos is a ndarray and its value is
pos :
ndarray[[ 0. 44. ...
-2
votes
1answer
63 views
numerical root finding for positive definite function in Python
I have a very complicated positive definite linear continuous function of a single variable k for which I am trying to find all roots in a given range of k; say -4 < k < 4.
Up until now I have ...
-1
votes
0answers
34 views
Numpy/Scipy Interpolation vs Matlab interp1 results differ
I have a 2D array of two variables A,B.Both these are results w.r.t a third variable C(1-D).
In matlab, I am using interp1 and getting B value at C, when A value at C is given as input.
function Y = ...
0
votes
1answer
47 views
A faster way to do these dataframe operations?
I am loading a dataframe from csv, and then performing the operations below. Loading the dataframe takes about 2 seconds. The other operations ( mainly the date conversions ) take 30 seconds. Is there ...
0
votes
2answers
37 views
Compare two numpy arrays by first Column and create a third numpy array by concatenating two arrays
I have two 2d numpy arrays which is used to plot simulation results.
The first column of both arrays a and b contains the time intervals and the second column contains the data to be plotted. The two ...
0
votes
1answer
17 views
CDF/PDF plot not showing
I am able to get a histogram from a Pandas dataframe to appear fine. I'd like to also show the PDf/CDF as line charts on the same plot.
My code:
import scipy.stats as stats
from scipy.stats import ...
0
votes
1answer
20 views
Get the expected array with SciPy's Fisher exact test?
SciPy allows you to conduct both chi square tests and Fisher exact tests.
While the output of the chi square test includes the expected array, the Fisher exact does not.
e.g.:
from scipy import ...
-1
votes
0answers
27 views
Non MKL based 64-bit numpy-scipy?
I need scipy on 64-bit python and unfortunately the binary distribution at http://www.lfd.uci.edu/~gohlke/pythonlibs/ does not work for me. It used to work, but not now... :( for some reason, MKL ...
0
votes
1answer
9 views
Install scipy and numpy on Win 64 machine (python 2.7)
I know there have been questions similar to this one before - I read them all and tried what they suggested
Hi,
I'm trying to install the scipy and numpy modules on my win 64 machine so I could call ...
0
votes
1answer
38 views
Multinomial sample generation in python
I am able to generate binomial samples from an array of probabilities in a desired size(output should be the same size of input probabilities array shape) using the following lines of code
prob_list ...
0
votes
2answers
39 views
Determine whether two complex numbers are equal
The following code causes the print statements to be executed:
import numpy as np
import math
foo = np.array([1/math.sqrt(2), 1/math.sqrt(2)], dtype=np.complex_)
total = complex(0, 0)
one = ...
1
vote
2answers
49 views
Faster rolling_apply on a Pandas DataFrame?
Improving upon this question which provided a clever solution for applying a function over multiple columns in a DataFrame, I'm wondering if the solution can be further optimized for speed.
...
0
votes
2answers
48 views
Python: How to find greater than N rows with non zero cells in greater than M common columns
I have n x m matrix and I want to find programatically N or more rows that contains non zero cells in more than M common columns.
For example. Here is the matrix:
matrix([[ 0., 0., 1., 1., 1., ...
1
vote
1answer
22 views
including a negative number in the log sum of exponents, in python
I want to use numpy's logsumexp() in python 2.7.
The formula I need to solve looks like this:
log ( 1 + e^a1 + e^a2 + e^a3 + ... e^an - e^ax )
The last term which is a negative number just has to ...
0
votes
1answer
48 views
Generating samples for any distribution
I want to generate 1000 samples from a distribution in python:
p(x1, ..., xn) = p(x1)p(x2|x1)(x3|x2)...p(xn|xn-1) where xn can take 0or 1
where p(x1=1) = 0.75, p(x_n = 1|x_n-1 = 1)=0.75 and p(x_n = ...
0
votes
1answer
33 views
contour plot with python loop and matplotlib
I can't figure out what's preventing me from getting a contour plot of this cost function. After much trial and error, I'm getting:
ValueError: zero-size array to reduction operation minimum which ...
0
votes
2answers
32 views
How to truncate a numpy array for values greater than a specified value?
Similar to this Matlab question, I am wondering how to truncate a numpy array by cutting off the values greater than a certain threshold value. The values of the array in question are in ascending ...
4
votes
0answers
91 views
What is the fastest way to extract given rows and columns from a Numpy ndarray?
I have a large (approx. 14,000 x 14,000) square matrix represented as a Numpy ndarray. I wish to extract a large number of rows and columns--the indices of which I know in advance, though it will in ...
1
vote
2answers
16 views
Taking a tensor product in python numpy without performing a sum
I have two tensors, each 2D, with a common long axis (eg 20.000) and diffenrent short axes eg one 9 the other 10). I want to end up with a 9X10X20000 tensor, such that for each location on the long ...
0
votes
1answer
33 views
Index Error: Index out of bounds when using numpy in python
I have a code that works fine when I have small CSV's of data but errors out when I try to run large CSV's through it. In essence this code is supposed to place 3 CSV's worth of data into 3 separate ...
-1
votes
2answers
24 views
Is there a complete list of Numpy data type namecode? [duplicate]
I'm reading some scipy code on Github and I came across this simple line of code
Y = zeros(newshape, 'D')
I tried to find out what does the 'D' mean but I couldn't. I wonder if there's a complete ...