Tagged Questions
-1
votes
1answer
16 views
Probability based randomzation of 2d Numpy array
How would I create a random 2D numpy matrix such that values closer to zero are given high probability?
0
votes
2answers
25 views
Replace values in numpy arrays not working
I have the following problem, and I'd be glad if somebody could explain to me why this is happening.
So, I have this numpy array:
[[ 0. 2.68530063 2.68530063 4.65107712 4.65107712 ...
2
votes
1answer
40 views
Extracting indices from numpy array python
I want the last 4 values of this equation.
Is there a better way to this in one step, like modifying the equation or another extraction technique other than using delete
a=5
d=2
n = np.cumsum(d ** ...
0
votes
1answer
33 views
Matrix addition/multiplication in numpy
Forgive me, it's been nearly 20 years since I've pulled out my matrix math.
I have a point in space:
point1 = (x, y)
I have a scaler:
scaler = 0.5
I have a transformational matrix:
...
0
votes
1answer
15 views
Stani's python editor unable to plot contour [on hold]
I'm using the following:
Ubuntu 12.04;
SPE editor 0.8.4.h;
Python Version 2.7.3;
wxPython version 2.8.12.1
I have written a small script in Python that plots a contour. Please find the script below:
...
1
vote
0answers
23 views
Looking for dataframe.apply() without shape restrictions
I want to do Spline interpolations separately on each column of a smaller dataframe timeseries to create a finer resolved dataframe time-series with a larger dimension than the original.
So, ideally ...
3
votes
1answer
85 views
Speed performance improvement needed. Using nested for loops
I have a 2D array shaped (1002,1004). For this question it could be generated via:
a = numpy.arange( (1002 * 1004) ).reshape(1002, 1004)
What I do is generate two lists. The lists are generated ...
0
votes
0answers
10 views
Python Shared Libraries: RTLD_GLOBAL segfault
I work with a python swig-wrapped C++ library. In it's __init__.py file, it sets the dlopen flag RTLD_GLOBAL before importing the shared object file containing the implementation code.
This causes ...
0
votes
2answers
37 views
Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()
I was unable to find anything describing how to do this, which leads to be believe I'm not doing this in the proper idiomatic Python way. Advice on the 'proper' Python way to do this would also be ...
0
votes
2answers
45 views
How to Convert (timestamp, value) array to timeseries [on hold]
I have a rather straightforward problem I'd like to solve with more efficiency than I'm currently getting.
I have a bunch of data coming in as a set of monitoring metrics. Input data is structured ...
1
vote
1answer
29 views
np.savetxt formatting - how to eliminate ',' and '('?
thank you for the help in my last question.
I have an additional question, which is really basic actually:
using the code bellow:
import numpy as np
data = ...
1
vote
2answers
28 views
numpy doesn't recognize data types in conversion
I would be grateful if you could help me with a solution you gave a while back in the link below:
Converting a list of ints, tuples into an numpy array
as you may recall you explained a method of ...
0
votes
2answers
24 views
Sorting lines of a text file using column with integers -
I need to sort the lines of a text file using the integer values of one of the columns
(the first one).
The file (coord.xyz) looks like this
9 1 -1.379785 0.195902 -1.197553
5 4 -0.303549 ...
-1
votes
2answers
63 views
Python syntax number + array
I occasionally meet this python construction: number + array
And I wonder what is the return value, is it number or array. What it does?
Example, where I met it is this:
def __init__(self, n): ...
1
vote
1answer
58 views
Summing along a function in a 2D array
Is it possible to place a linear function over a 2D array and sum all the elements in the 2D array that coincide with the function? So for example, I would have a 2D array shaped say (400, 500). Now ...
0
votes
1answer
22 views
Trying to print out the decision tree for a forest from scikit-learn ensemble
I am trying to print out the decision tree for a forest from scikit-learn ensemble: For example for a DecisionTreeClassifier, I would use:
from sklearn import tree
clf = ...
2
votes
1answer
21 views
whosmat Attribute error in python
I have a .mat file and I want to list variables of this file:
import scipy.io as sio
import numpy as np
mat_contents = sio.loadmat('dga.mat') #read the .mat file
mat_variables = ...
1
vote
1answer
37 views
scipy.polyfit(x, y, 100) would be 100th order polynome, but matplotlib.pyplot.legend displays 53?
I'm having a hard time figuring out why my plt.legend displays the wrong polynome degree. It says 53 instead of 100. My code would go like this:
import scipy as sp
import numpy as np
import urllib2
...
2
votes
0answers
55 views
Efficient way to get largest box sizes of similar elements from a 2D numpy array (or pandas dataframe) [duplicate]
Basically I have a 2 dimensional numpy array filled with boolean values.
For example:
[[0,0,0,1],
[0,0,0,1],
[1,1,1,1],
[1,1,1,1],
[1,0,0,0],
[1,0,1,1]]
I need to figure out where the largest ...
0
votes
1answer
24 views
numpy vstack throwing dimension error
I am monitoring the serial port and attempting to plot data in Matplotlib as it arrives. Because the data arrives at irregular intervals, I am using an approach to append data - similar to this ...
0
votes
0answers
40 views
PyArrayObject definition is missing
I'm trying to compile some C code (CUDA) [1], which relies on Numpy package:
/cuda-convnet-vs-proj/src/util.cu(69): error : identifier "PyArrayObject" is undefined
I installed Anaconda (on ...
1
vote
1answer
16 views
How to pickle numpy MaskedArray subclass
I'm having trouble getting a NumPy MaskedArray subclass to round-trip through pickle and preserve the extra subclass attributes. Here is an example:
import numpy as np
import cPickle as pickle
from ...
0
votes
1answer
42 views
Using Python for FFTs on audio files - sampling rate
I've been trying to find some frequencies that are most dominant in a WAV file. I've found out that I can use the python wave library, as well as scipy.io.wavfile for reading the audio file.
If the ...
2
votes
3answers
83 views
Fastest way for working with itertools.combinations
I need to speed up the function below :
import numpy as np
import itertools
import timeit
def combcol(myarr):
ndims = myarr.shape[0]
solutions = []
for idx1, idx2, idx3, idx4, idx5, idx6 ...
1
vote
3answers
61 views
Find multiple maximum values in a 2d array fast
The situation is as follows:
I have a 2D numpy array. Its shape is (1002, 1004). Each element contains a value between 0 and Inf. What I now want to do is determine the first 1000 maximum values and ...
0
votes
2answers
30 views
Python & Numpy: Iterating over specific axes with multi_index?
I have an array with five axes:
colors = numpy.zeros(3, 3, 3, 6, 3))
I want to iterate over it using multi_index like in the second example from this link, but instead of iterating over the entire ...
0
votes
0answers
44 views
Using Scipy.optimize method='SLSQP' returns initial guess
I try to dig more into optimization of functions depending on multiple variables with scipy
I have a function returning prediction from a data mining tool after calling this tool with a batch file.
...
1
vote
1answer
35 views
Correlating vector data with numpy
I have a time series of vector data -- each point being a 2D vector. I would like to calculate an autocorrelation (or something like it -- excuse me if I'm misusing the language here). Let's say the ...
3
votes
0answers
56 views
Matplotlib & Numpy incompatibility with some Pandas functions? - integer is required
First of all, I am using '2.7.3 | 64-bit, pandas 0.12.0, and numpy 1.8.0. I am following this tutorial on Pandas time series, however when I get to this:
...
3
votes
2answers
24 views
python EOF error when reading csv data with pylab (matplotlib)
I am trying to plot data from a csv file using matplotlib (in Python 2.6), but I am having some trouble with reading in the data from csv:
import pylab
# works fine - manually output data for debug
...
0
votes
0answers
25 views
Installing python module bottleneck error
I'm trying to install the bottleneck python module and I'm getting the following error:
$ pip install bottleneck
In file included from ...
3
votes
2answers
83 views
Sample uniformly from multisets
Given the set of integers {1,...,n}, I would like to sample uniformly from the binom{n+k-1}{k} distinct multi-subsets of size k. Is there an efficient way of doing this?
For example, the set ...
0
votes
1answer
31 views
Defining variables: problems with program logical flow
I'm currently trying to implement the following algorithm for finding max.-margin decision boundaries (for use in an SVM):
let D = {(x1, y1), (x2, y2), . . . , (xl, yl )} ⊂ Rn ×{+1,−1}
r ← max{|x| | ...
2
votes
2answers
39 views
Python/Numpy: Setting values to index ranges
Using Numpy, I can create a 5-dimensional array like this:
>>> faces = numpy.zeros((3, 3, 3, 6, 3))
I want (all indexes, all indexes, 0, 4) to be set to (1., 1., 1.). Is this possible by ...
0
votes
1answer
57 views
Iterating with numpy with different indexes
Say I have a for loop using range as shown below. Is there a good way to eliminate the for loop and use numpy arrays only?
y =[146, 96, 59, 133, 192, 127, 79, 186, 272, 155, 98, 219]
At=3
Bt=2
...
0
votes
2answers
52 views
Python: Defining a minimum bounding rectangle
I have data in the following format, a list of 2d x,y coordinates:
[(6, 7), (2, 4), (8, 9), (3, 7), (5, 4), (9, 9)]
and I'm trying to iterate through the list to find the minimum bounding box in ...
1
vote
1answer
44 views
Iterating over a numpy array with enumerate like function
I want to numpy arrays into some of my code. I am trying to iterate over an array.
import numpy as np
a=10.0
b=55.0
y=np.asarray([11,30,54,7,22,5,15,65,15,6])
I =[y[i] / (a + (i+1) * b) for i in ...
0
votes
1answer
21 views
Create a Numpy scalar from dtype
I'm trying to create a numpy scalar of a specified dtype. I know I could do, say, x = numpy.int16(3), but I don't know the dtype in advance.
If I were to want an array then
dtype = int
x = ...
1
vote
2answers
40 views
Numpy arrays assignment operations indexed with arrays
I have an array y with indexes of values that must be incremented by one in another array x
just like x[y] += 1, This is an example:
>>> x = np.zeros(5,dtype=np.int)
>>> y = ...
1
vote
1answer
45 views
How can I regularize a linear regression with scipy's curve_fit?
I have recently become proficient at using Python/scipy curve_fit to perform linear regression. However, with higher order polynomials, my data is sometimes overfit.
How can I add regularization to ...
2
votes
1answer
36 views
Parsing specific columns from a dataset in python
I have a dataset with multiple columns and I am only interested in analyzing the data from six of the columns. It is in a txt file, and I want to load the file and pull out the following columns (1, ...
2
votes
4answers
41 views
Issue adding 2D arrays in numpy
I have two arrays a and b of dimensions 3x1 and 3x3 and I want to sum them up like here:
>>> a = np.arange(3).reshape(3,1)
>>> a
array([[0],
[1],
[2]])
>>> b ...
1
vote
1answer
65 views
converting stft to chroma and plotting the result
I am trying to convert stft of a wav file into chromagram.
Here's my code :-
def stft(x,fs,framesize,hopsize):
frame = int(framesize*fs)
hop = int(hopsize*fs)
w = scipy.hamming(frame)
...
1
vote
1answer
27 views
scipy PchipInterpolator Error: 'array cannot be safely cast to required type'
I would like to do some piecewise cubic hermite interpoaltion on some input data from pyaudio:
#input comes as string and is converted to int16
numpyData = numpy.fromstring(inData, dtype=numpy.int16)
...
0
votes
1answer
25 views
Improving performance of Cronbach Alpha code python numpy
I made some code for calculating Cronbach Alpha that works. But I am not too good using lambda functions. Is there a way to reduce the code and improve efficiency by using lambda instead of the svar() ...
3
votes
1answer
56 views
Numpy — Split 2D array into sub-arrays based on indices
I have an array that I'd like to split into sub-arrays based on the obvious and non-overlapping rectangles:
>>> A = array([[ 0., nan, 2., nan, 4., nan, 6, nan],
[ ...
0
votes
2answers
29 views
Mismatch with scikit-learn fit() method when trying to plot data set from csv instead of generating it
Originally I uses an scikit-learn snipit to generate my data set:
# Create a random dataset
rng = np.random.RandomState(1)
X = np.sort(5 * rng.rand(80, 1), axis=0)
y = np.sin(X).ravel()
y[::5] += 3 * ...
6
votes
1answer
78 views
How to prevent adding two arrays by broadcasting in numpy?
Numpy has a very powerful broadcasting mechanism. It can even add 1x2 and 2x1 array without any warning. I don't like such behaviour: with 99% percent probability such addition is a consequence of my ...
0
votes
1answer
40 views
Out of memory when DataFrame.resample() is called in pandas on small dataset
I have a DataFrame that has a number of string columns and a datetime column. I want to resample the datetime columns appropriately using pandas df.resample(). For instance, my data looks like:
from ...
0
votes
1answer
21 views
Import Error with Numba: Wrong ELF class: ELFCLASS64
I'm trying to use continuum analytics modules, specifically numpy and numba. When I try to import one of these modules I get
ImportError: ...