Tagged Questions
0
votes
0answers
25 views
Python visualising 3D numpy arrays
I am looking to visualize some 3D numpy arrays in a similar manner I would do it with pyplot.imshow with 2D array.
It looks like the best option would be to use the mayavi package. Unfortunately, I ...
0
votes
1answer
22 views
Shapes of the np.arrays, unexpected additional dimension
I'm dealing with arrays in python, and this generated a lot of doubts...
1) I produce a list of list reading 4 columns from N files and I store 4 elements for N times in a list. I then convert this ...
1
vote
1answer
21 views
Quickly read HDF 5 file in python?
I have an instrument that saves data (many traces from an analog-to-digital converter) as an HDF 5 file. How can I efficiently open this file in python? I have tried the following code, but it seems ...
0
votes
1answer
33 views
Reading string and data from a file (Python)
I'd wanna to read time strings and data from a file but when I used loadtxt i cant read string and numbers at the same time because strings are not float. So i tried using genfromtxt and use ...
4
votes
2answers
43 views
Find the indices of non-zero elements and group by values
I wrote a code in python that takes a numpy matrix as input and returns a list of indices grouped by the corresponding values (i.e. output[3] returns all indices with value of 3). However, I lack the ...
0
votes
1answer
28 views
convert string numpy array to a ascii numpy matrix
I have been looking for an efficient way for converting a string numpy array to a two dimensional ASCII matrix in python. So for this is the best that I could come up with
def ...
0
votes
0answers
25 views
Find roots using scipy.optimize.fsolve. What went wrong?
I have the code:
import numpy as np
import scipy.optimize
Basic variables:
eee=0.289;
nn=0.63;
E1k=0.0935;
pp=1.25;
B1k=0.12;
v1k=0.126;
Bkk=3.14;
VKb=0.76;
rKb=1.754;
Motion model, these ...
0
votes
1answer
54 views
Python toe find the row index
I have the 2 inputs, namely a numpy
array (representing a matrix H) and a list (row). Both the matrix (H) and
list (row) only contain integer values.
The function must return the row index (of the ...
0
votes
1answer
15 views
How to plot a boxplot using matplotlib with discontinuous y intervals on the y-axis?
I have the following data set for which I need to generate the boxplot using matplotlib:
...
0
votes
1answer
32 views
new columns in index created inside for loop
I am trying to create something that measures up days and down days in stocks as measured by a higher or lower close than the day before. This is displayed as a 1 for an 'up day' and a -1 for a 'down ...
0
votes
0answers
19 views
Cython+NumPy - compiler not using numpy.pyd
I have a code that uses numpy and I want to compile it using Cython. I added the cimport directive:
import numpy as np
cimport numpy as np
I am on Windows 7, compiling using distutils with gcc ...
2
votes
0answers
19 views
Scipy labels and measuring max pixel in each label
So I want to measure the max pixel and average of pixels in each label(in multiple array) using scipy.
for example
(img , other is a numpy array of an opened tif)
import numpy as np
import ...
1
vote
1answer
16 views
Convert a 2D numpy array into a 3d numpy array representing a grayscaled image
I am using OpenCV with numpy and Python. I have a 2D uint8 numpy array. The values represent the local densities of over-threshold pixels from a thresholded image. I would like to convert this into a ...
0
votes
1answer
35 views
Python 'astype' not working
I am currently using Spyder from Anaconda and I am trying to convert an array containing type float to type int:
x = np.array([1, 2, 2.5])
x.astype(int)
print x
The result still comes out ...
2
votes
1answer
44 views
“stacking” arrays in a new dimension?
Consider, for reference:
>>> x, y = np.ones((2, 2, 2)), np.zeros((2, 2, 2))
>>> np.concatenate((x, y, x, y), axis=2)
array([[[ 1., 1., 0., 0., 1., 1., 0., 0.],
[ 1., ...
1
vote
2answers
26 views
numpy.resize() rearanging instead of resizing?
I'm trying to resize numpy array, but it seems that the resize works by first flattening the array, then getting first X*Y elem and putting them in the new shape. What I want to do instead is to cut ...
1
vote
2answers
26 views
outputting large matrix in python from a dictionary
I have a python dictionary formatted in the following way:
data[author1][author2] = 1
This dictionary contains an entry for every possible author pair (all pairs of 8500 authors), and I need to ...
0
votes
1answer
17 views
VTK to Maplotlib using Numpy
I want to extract some data (e.g. scalars) from a VTK file along with their coordinates on the grid then process it in Matplotlib. The problem is I dont know how to grab the point/cell data from the ...
1
vote
2answers
26 views
Loadtxt can't find file
I've pasted the file into every location I can think of and it still won't find it, am I doing something wrong?
from numpy import *
x,y = loadtxt("filename" , unpack=True)
always comes up with ...
0
votes
1answer
39 views
What is the equivalent of Matlabs differentiate function in numpy?
I have a function and I use polynomial approximation of the function in Matlab, then I calculate the differentiate of the function
ppp = fit(x,y, 'poly9')
polydiff = differentiate(ppp, x)
I would ...
0
votes
0answers
23 views
numpy array creation using np.indices() [on hold]
Can somebody explain in detail how np.indices() array creation is used and some useful examples? I have read the numpy documentation but I cannot really understan the logic behind and why is this ...
2
votes
5answers
80 views
Return zero value if division by zero encountered
I have two lists a and b of equal length. I want to calculate the sum of their ratio:
c = np.sum(a/b)
how can I have a zero (0) value in the summation coefficient when there is division by zero?
...
3
votes
2answers
35 views
What is the Python numpy equivalent of the IDL # operator?
I am looking for the Python numpy equivalent of the IDL # operator.
Here is what the # operator does:
Computes array elements by multiplying the columns of the first array
by the rows of the ...
0
votes
0answers
29 views
Overflow Error in Neural Networks implementation
I m trying to build my own implementation of neural network back propagation algorithm. The code i have written for training is this so far,
def train(x,labels,n):
lam = 0.5
w1 = ...
0
votes
1answer
25 views
Matplotlib(python) - drawing stationary signal
How can I draw plot of formula: x(t)=cos(2π·10t)+cos(2π·25t)+ cos(2π· 50t) +cos(2π·100t)
1
vote
1answer
23 views
plotting 3d vectors (arrays) in python
Using numpy Packet i produced vectors (arrays) contain x,y,z-coordinates of several atoms in a protein. I would like to plot these vectors.
Does anybody know how to do this?
Since I could't plot the ...
0
votes
2answers
35 views
How do I get a Pandas TimeSeries for user sessions (using Pandas or Numpy)
I've got some data which has the login and logout times for a series of users.
Input:
Login Logout
User_1 10:25AM 6:01PM
User_2 8:58AM 5:12PM
User_3 9:23AM 1:35PM
...
0
votes
0answers
35 views
Python categorize datatypes
I plan to make a 'table' class that I can use throughout my data-analyzis program to store gathered data to. Objective is to make simple tables like this:
ID Mean size Stdv Date measured ...
0
votes
3answers
34 views
How to print numpy array in binary representation mode
I have a following numpy array
a = np.array([[1,2,3,4 ,11, 12,13,14,21,22,23,24,31,32,33,34 ]],
dtype=uint8)
when I print a i am getting the following output
[[ 1 2 3 4 11 12 13 14 21 22 ...
0
votes
1answer
54 views
Python array, unnecessary space
I am trying to read a file and create an array from it. The file is as follows:
1 0
0 1
The code is:
line = file.read()
array = np.fromstring(line.strip(),dtype = bool, sep = " ")
...
1
vote
2answers
27 views
What is the best way to take np.percentile along an axis ignoring nans?
Is there a reasonably fast way to do np.percentile(ndarr, axis=0) on data containing NaN values?
For np.median, there is the corresponding bottleneck.nanmedian ...
0
votes
2answers
30 views
lambda function in class header
I am trying to create nan value for integer. the design i am thinking about is the following.
I need to create and isnan lambda function in the class definition header but it returns an error
import ...
1
vote
1answer
19 views
Accessing ndarray and discarding invalid positions - Python
I have one question about accessing a matrix position that in fact does not exists.
First, I have an matrix with rows rows and cols columns. From this matrix, I have to get sets of n x n sub ...
1
vote
1answer
28 views
Numpy read complex numbers from text file
I have used numpy to save a matrix of complex numbers. The output file looks like that:
(1.100412357301083777e-02+1.471303433818593742e-02j) ...
2
votes
2answers
21 views
Numpy: get only the array rows that have a value in an interval
I have a numpy array which which has a shape of (10, 3) and looks like:
10 | xxx | yyy
11 | xxx | yyy
13 | xxx | yyy
14 | xxx | yyy
15 | xxx | yyy
17 | xxx | yyy
19 | xxx | yyy
..............
What ...
1
vote
1answer
22 views
Less code lines for scaling and stacking columns in numpy
I just started using iPython and numpy. I am sure that it is possible to do the same thing as below with less code.. I would like to scale all columns (=dimensions of a datapoint, which is the row) to ...
2
votes
2answers
53 views
Optimize A*x = B solution for a tridiagonal coefficient matrix
I have a system of equations in the form of A*x = B where A is a tridiagonal coefficient matrix. Using the Numpy solver numpy.linalg.solve I can solve the system of equations for x.
See below for how ...
1
vote
1answer
14 views
python generator returning ndarray
I'm having the following odd behavior with a generator that returns a numpy array. In the real application, I am using scipy.sparse to implement an iterative linear algebra solver: The below is a ...
2
votes
2answers
69 views
Python numpy or pandas equivalent of the R function sweep()
What is numpy or pandas equivalent of the R function sweep()?
To elaborate: in R lets say we have a coefficient vector (say beta - numeric type) and an array (say data - 20x5 numeric type). I want to ...
0
votes
1answer
9 views
Indicating format of multiple numbers in numpy.savetxt
I want to save an array using numpy.savetxt. The array contains eight numbers. Only the format of the first number is different with respect to the latter seven. I know I can set the format of numbers ...
0
votes
3answers
24 views
unsupported operand type(s) for +: 'numpy.float64' and 'str'
I am trying to find standard deviation and mean from an input file (input.txt) which consists of 5000 data in one column and I want output in the file 'outfile.txt'. My code is as follows:
import ...
3
votes
1answer
44 views
Not getting the expected speedup with Cython
Here are two code samples
def hough_transform_1(active_points, size_trame, size_max_song):
m = np.linspace(0.95, 1.05, 11)
p = np.linspace(-size_trame, size_max_song, size_max_song + ...
2
votes
1answer
29 views
Extending numpy arrays
I'm new to Python/numpy.
I'm trying to extend numpy.array to give it some functions that make it nice for representing images (e.g. convert to greyscale etc).
import numpy as np
import cv2
from ...
1
vote
2answers
22 views
Numpy: Create a mask array to select rectangle
Is there a way to generate an array, masking a rectangular area, without the need to initialize an empty array first?
mask = np.zeros((10,10), dtype=bool)
mask[10/2:,10/2:] = True
Im looking for ...
0
votes
1answer
26 views
How to do curve_fit in python
I need to curve fit a set of data using y = x / (a + x), where a is the parameter that I am required to get from this excercise.
import numpy as np
import matplotlib.pyplot as plt
from ...
4
votes
3answers
48 views
Make subset of array, based on values of two other arrays in Python
I am using Python. How to make a subselection of a vector, based on the values of two other vectors with the same length?
For example this three vectors
c1 = np.array([1,9,3,5])
c2 = ...
0
votes
0answers
35 views
Train OLS model with pandas concurrently
I want to train multiple OLS models (in fact, the number is about 500 in total) with pandas. Could I do this in a batched fashion?
Here is a simplified case, in which I want to train 5 models, say ...
2
votes
1answer
46 views
Finding the distance of points to an axis
I have an array of points in 3d Cartesian space:
P = np.random.random((10,3))
Now I'd like to find their distances to a given axis and on that given axis
Ax_support = array([3,2,1])
Ax_direction = ...
1
vote
0answers
21 views
Scipy won't recognize my BLAS path when installing
I want to install scipy on a machine where I am not root following the instruction I found on this page but I meeting a BLAS not found error despite the fact that BLAS is install and "properly ...
1
vote
1answer
26 views
Given void when taking one element from record array
Say, I have a record array.
RA = array([('professor', 'class1', '1'), ('professor', 'class1', '1'),
('professor', 'class1', '0'), ('doctor', 'class3', '1')],
dtype=[('f0', 'S25'), ...