1
vote
2answers
9 views

numpy array elementwise multiply a panda timeseries

I have these two data structures: a = np.array([1,2,3]) ts = pd.TimeSeries([1,2,3]) What I want to get at the end is: 1 2 3 2 4 6 3 6 9
0
votes
1answer
12 views

Logical indexing in Numpy with two indices as in MATLAB

How do I replicate this indexing done in MATLAB with Numpy? X=magic(5); M=[0,0,1,2,1]; X(M==0,M==2) that returns: ans = 8 14 I've found that doing this in Numpy is not correct, since it does ...
1
vote
2answers
13 views

Numpy savez / load thousands of arrays, but not in one step

I would like to store approx 4000 numpy arrays (of 1.5 MB each) in a serialized uncompressed file (approx 6 GB of data). Here is an example with 2 small arrays : import numpy d1 = { 'array1' : ...
1
vote
2answers
15 views

Numpy savetxt to a string

I would like to load the result of numpy.savetxt into a string. Essentially the following code without the intermediate file: import numpy as np def savetxts(arr): np.savetxt('tmp', arr) ...
4
votes
2answers
29 views

Find Value that Partitions two Numpy Arrays Equally

I have two arrays (x1 and x2) of equal length that have overlapping ranges of values. I need to find a value q such that l1-l2 is minimized, and l1 = x1[np.where(x1 > q)].shape[0] l2 = ...
3
votes
2answers
29 views

Pythonic way of detecting outliers in one dimensional observation data

For the given data, I want to set the outlier values (defined by 95% confidense level or 95% quantile function or anything that is required) as nan values. Following is the my data and code that I am ...
2
votes
1answer
22 views

IPython error row and column

Is it possible in IPython interactive console to show not only the row at which the error is originating but also the column? For example in this script, I know that the problematic line is 934 but I ...
1
vote
1answer
34 views

Compare Numpy and Matlab code that uses random permutation

I'm having problems to compare the output of two code because of random number state. I'm comparing the MATLAB randperm function with the output of the equivalent numpy.random.permutation function ...
2
votes
2answers
34 views

putting value of one array into a list in python [duplicate]

I am very new to python and I have a line of code print docClassifier.predict(temp) which basically prints an array of this format [0,0,1,1,1,0....]. Now I want to store this array in a list for ...
0
votes
0answers
17 views

error when installing numpy for pypy2.2.1

I am trying to use pypy. My python scripts are using numpy. So when I used pypy 1.9.0 it showed me this: "The 'numpy' module of PyPy is in-development and not complete. " ImportError: The '`numpy' ...
0
votes
1answer
29 views

Categorize and calculate something in python

I have following input file O 2.05151 39.51234 0.00000 O 32.69451 1.48634 8.31300 O 10.53351 21.63634 7.95400 O 30.37451 20.74134 0.99700 Si 8.06451 19.19434 10.21700 Si ...
0
votes
0answers
24 views

Converting dates from HDF5 dataset to numpy array

I have a HDF5 dataset having dates matrix which I'm loading in my Python script and want to use it as numpy array - >>> mat = h5py.File('xyz.mat') >>> dates = mat['dates'] ...
0
votes
1answer
14 views

Plotting a Discriminant Function for Normal Densities via Matplotlib

I want to plot the general discriminant function for normal densities for some random data. I have no idea how I would go about it via matplotlib, I hope anyone could help me a little bit. The ...
2
votes
2answers
51 views

How to eliminate for-loop and use list comprehension when using numpy array?

I am trying to avoid using for-loop with numpy array. If I have a code that looks like below: psimaps = [np.zeros((10,10)) for i in range(len(features)-1)] for k in range(len(features)-1): if ...
-1
votes
0answers
21 views

Graph in different colour according to classification

I have a CSV. Each row corresponds to a different item. Each item is a class of either 0 or 1. I have a column in my CSV which represent the "category" of an item. I am trying to graph this in a ...
2
votes
1answer
28 views

percentile rank in pandas in groups

I can't quite figure out how to write function to accomplish a grouped percentile. I have all teams from years 1985-2012 in a data frame; the first 10 are shown below: it's currently sorted by year. ...
0
votes
1answer
30 views

Generating perfect random gaussian numbers

I tried to generate the series of random numbers with gaussian distribution. So, I used numpy.random.normal(mean,standard deviation,size). However, when I converted these numbers into probabability ...
2
votes
3answers
48 views

Check that all rows in numpy array are unique

I have a 4 column array: A=array([[100,1,500,1], [100,1,501,1], [101,1,501,1], [102,2,502,2], [500,1,100,1], [100,1,500,1], [502,2,102,2], ...
1
vote
1answer
30 views

Read file with missing data with loadtxt (numpy)

When I try to read the data below with loadtxt('RSTN') I got an error, then I tried to complete this missing data using genfromtxt('RSTN',delimiter=' ') But I got an error like this Line ...
1
vote
0answers
21 views

Why python raise a runtime error while i run numpy.percentile for equalization by scikit-image?

I take the equalization code from here import numpy as np from skimage import morphology from skimage import color from skimage import io from matplotlib import pyplot as plt from skimage import ...
2
votes
1answer
28 views

Generating a probability from a pdf?

I have some data that is normally distributed and to which I have fitted a pdf. However, I want to get the probability of the likelihood of a given value from the dataset occurring. From my ...
0
votes
2answers
20 views

Vertical Histogram in Python and Matplotlib

How can I make a vertical histogram. Is there any option for that or should it be built from the scratch? What I want is the upper graph to look like the below one but on vertical axis! from ...
2
votes
3answers
35 views

determine number of rows of an (M,N) array and (M,) array with same function

I have a loop: for i in range(np.shape(data)[1]): item1 = data[i,0] Now this works for data which has a shape (M,N) but when it is a single row, it is (M,) and I can not access the [1] index of ...
2
votes
1answer
22 views

jacobian with numdifftools in python

i'm kind of stuck and couldn't find an answer that helped: i have a system of differential equations and need to calculate the jacobian. the code below throws AttributeError: 'list' object has no ...
5
votes
4answers
74 views

Construct single numpy array from smaller arrays of different sizes

I have an array of values, x. Given 'start' and 'stop' indices, I need to construct an array y using sub-arrays of x. import numpy as np x = np.arange(20) start = np.array([2, 8, 15]) stop = ...
0
votes
0answers
33 views

How to save a Python dtype('O') in an HDF5

According to this link the NumPy generic object ("O") datatype is not supported by h5py but I really need to store it cause I have designed my file and store other datatype into it now it's really ...
2
votes
1answer
46 views

“valid” and “full” convolution using fft2 in Python

This is an incomplete Python snippet of convolution with FFT. I want to modify it to make it support, 1) valid convolution 2) and full convolution import numpy as np from numpy.fft import fft2, ...
1
vote
1answer
26 views

making numpy.nanargmin return nan if column is all nan

Is it possible to use numpy.nanargmin, so that it returns numpy.nan, on columns where there are only nans in them. Right now, it raises a ValueError, when that happens. And i cant use numpy.argmin, ...
2
votes
1answer
33 views

python C extension of numpy error in 64-bit centos, but Ok in 32-bit centos

It's supposed to be called like this: Pyentropy(np.array([1,2,2,1,1,1],int), 0) or Pyentropy(np.array([1,2,2,1,1,1],int), 1) It meant to calculate the entropy of [1,2,2,1,1,1] But in Pyentropy, ...
0
votes
1answer
17 views

How does the axis parameter from NumPy work?

Can someone explain exactly what the axis parameter in NumPy does? I am terribly confused. I'm trying to use the function myArray.sum(axis=num) At first I thought if the array is itself 3 ...
1
vote
1answer
8 views

Saving dictionary of header information using numpy.savez()

I am trying to save an array of data along with header information. Currently, I am using numpy.savez() to save the header information (a dictionary) in one array, and the data in another. data ...
0
votes
1answer
18 views

Max value of array won't save ASCII text to file

I am reading points from a frequency spectrum graph into an array like this: self.iq_fft = self.dofft(self.iq)#Gets values of all data point in block (in dB) x = self.iq_fft #puts values into x for ...
0
votes
1answer
35 views

Is this a Numpy Bug? Numpy ValueError: Object is not aligned [duplicate]

I tried the following commands: >>> a = np.matrix([[1,2],[3,4]]) >>> a matrix([[1, 2], [3, 4]]) >>> b = np.matrix([[0,1],[0,1]]) >>> b matrix([[0, 1], ...
0
votes
1answer
27 views

Index Out of Bounds Python in Neural Network script

I am new to python and this is (unfortunately) the first time I've wrote a relatively longer section of code in it. I have been following a tutorial for writing a neural network but have run across ...
2
votes
2answers
44 views

How to apply multiple functions to numpy array?

I know how to vectorize() or apply function along axis .. but my case is a bit different. I have 1D array (z) that contains 1 or 0 and then I have a 2D array (x). I want to apply two different ...
3
votes
2answers
60 views

Difference between A[1:3][0:2] and A[1:3,0:2]

I can't figure out the difference between these two kinds of indexing. It seems like they should produce the same results but they do not. Any explanation?
2
votes
1answer
27 views

Creating a matrix of joint number of hits from two columns using numpy/pandas

I have 2 large columns of data (some 1.5million values). They are structured as : col1 = [2,2,1,4,5,4,3,4,4,4,5,2,3,1,1 ..] etc., col2 = [1,1,8,8,3,5,6,7,2,3,10.........] etc., I want to ...
10
votes
2answers
168 views

Can I speed up this basic linear algebra code?

I was wondering whether it is possible to optimise the following using Numpy or mathematical trickery. def f1(g, b, dt, t1, t2): p = np.copy(g) for i in range(dt): p += t1*np.tanh(np.dot(p, ...
0
votes
2answers
47 views

How to check if all elements of a numpy.array are of the same data type?

I have few numpy arrays, which can be formatted as [1.525, 2.565, 6.367, ...] # elements are float numbers or ['', '', '', ...] # elements are empty strings I'd like to find out if all the ...
1
vote
1answer
50 views

translate Python in to Unity C# - Maths OR how to find Shortest distance between two skew lines in 3D space

I think it'll be enough if I understand what np.linalg.norm(A) np.linalg.det([t, _A, cross]) np.cross(_A, _B) does Python code founded here 6. answer by @Fnord I was looking at their doc, but I ...
2
votes
3answers
36 views

Method for reading a string of coordinates and taking out intgers (Python)

Lets say that I have a string that represents points on the x, y axis "(1,2), (10,20), (100,200)" what is the best method of abstracting the coordinate integers for numerical analysis? So this is ...
2
votes
1answer
34 views

Extracting specific values from .npy file

I have a .npy file of which I know basically everything (size, number of elements, type of elements, etc.) and I'd like to have a way to retrieve specific values without loading the array. The goal is ...
1
vote
1answer
31 views

Widening Pandas Data Frame, Similar to Pivot or Stack/Unstack

My problem is probably best explained with an example: What I have: ID0,ID1,Time,Data0,Data1 1 1 10 'A' 93 1 2 10 'A' 55 1 1 12 'A' 88 1 2 12 'B' 66 2 3 102 ...
4
votes
5answers
68 views

average of all rows corresponing to all unique rows

I have a numpy array with two columns: A = [[1,1,1,2,3,1,2,3],[0.1,0.2,0.2,0.1,0.3,0.2,0.2,0.1]] for all uniques in first column, I want average of the values corresponding to it. For example B = ...
0
votes
0answers
34 views

large matrix containing floating values to grayscale image in Python [on hold]

I am trying to convert a large matrix to a grayscale image. The matrix contains intensity values which are floating point numbers. I am trying to use this code: import Image, numpy, scipy import ...
2
votes
2answers
55 views

Passing numpy string-format arrays to fortran using f2py

My aim is to print the 2nd string from a python numpy array in fortran, but I only ever get the first character printed, and it's not necessarily the right string either. Can anyone tell me what the ...
0
votes
1answer
27 views

Pb converting a list of pandas.Series into a numpy array of pandas.Series

I would like to convert a list of pandas.Series into a numpy array of pandas.Series. But when I call the array constructor, it also converting my Series. >>> l = ...
1
vote
0answers
23 views

Passing integer Numpy ndarray to ctypes function

I'm having an issue passing a Numpy ndarray of integers to a C function via ctypes. Below is a MWE that shows the problem. First the C function, it just takes an array as an argument prints its ...
1
vote
0answers
40 views

Fast array/list type for holding numpy ndarrays

I have a lot of list of numpy ndarrays, of different sizes, in my code. (I also have lists of lists of numpy ndarrays, but that is less issue as those lists are small (<5 elements).) I have learn ...
0
votes
0answers
15 views

Python/OpenCV show saved image not working

I have a saved image that I would like to be displayed in a window when I call a function within my code. The current code I am using to display the image is below, savedPath = outputimg + '\\' + ...

15 30 50 per page