4
votes
0answers
25 views

rearranging rows in a big numpy array zeros some rows. How to fix it?

I am working with numpy and the following data (all matrices have all cells nonegative): >>> X1.shape (59022, 16) >>> X3.shape (59022, 84122) >>> ind.shape (59022,) ...
0
votes
1answer
28 views

amend code to return True or False for numbers in sequence

import numpy as np import re def validate(seq): ...
1
vote
0answers
15 views

CDF Cumulative Distribution Function Error

I am trying to plot a CDF for one column in multi-column data file. When only one column is present in data file it plots fine. When I try to grab a particular column from data it gives me error. I ...
2
votes
0answers
17 views

Cython Numpy warning about NPY_NO_DEPRECATED_API when using MemoryView

I am converting a Cython memoryview to a numpy array (to be able to use it in pure Python code): from libc.stdlib cimport realloc cimport numpy as np DTYPE = np.float64 ctypedef np.float64_t DTYPE_t ...
0
votes
0answers
32 views

How dot product works inside numpy?

suppose for example >>> import numpy as np >>> a = np.arange(4) >>> b = np.arange(16).reshape((4,4)) >>> c = a.dot(b) >>> c array([56, 62, 68, 74]) how ...
1
vote
2answers
42 views

Summing and removing repeated elements of Numpy Arrays

I have 4 1D Numpy arrays of equal length. The first three act as an ID, uniquely identifying the 4th array. The ID arrays contain repeated combinations, for which I need to sum the 4th array, and ...
0
votes
0answers
6 views

sinc interpolation of images in python

I am trying to interpolate a 3D image defined on some regular grid onto another grid using sinc interpolation. I have done similar thing using linear and spline interpolation using the ndimage ...
4
votes
1answer
44 views

pandas and numpy thread safety

I'm using pandas on a web server (apache + modwsgi + django) and have an hard-to-reproduce bug which now I discovered is caused by pandas not being thread-safe. After a lot of code reduction I ...
2
votes
1answer
22 views

SymPy lambdify raises OverflowError: math range error

So, I have this code from __future__ import division, print_function import sympy as sp import numpy as np from sympy.utilities.lambdify import * u = np.random.uniform(4, 6, 500) w, k = ...
0
votes
0answers
11 views

How to take an exponential of a quantum object in Python's QuTiP

I want to take all the elements of a quantum object rho1 (which is basically a matrix/array) and calculate the exponential of the elements to get a matrix/array rho2. How do I do this? Obviously exp ...
5
votes
2answers
48 views

Strange asignment in numpy arrays

I have a numpy array A with n rows of size 3. Each row is composed by three integers, each one is a integer which refers to another position inside the numpy array. For example If I want the rows ...
3
votes
2answers
35 views

Sum SymPy expression over NumPy array

So, if I do this import sympy as sp import numpy as np u = np.random.uniform(0, 1, 10) w, k = sp.symbols('w k') l = sum(1 - sp.log(k + w) + sp.exp(k + w) for k in u) I get what I want (a symbolic ...
-1
votes
0answers
27 views

Finding the peak of data steeply sloped on one side and shallow sloped on the other

I have data that looks like this: Sometimes the data has a higher point in the middle of the shallow slope I want to find a way to filter the data such that it smooths it and leaves the first ...
4
votes
1answer
48 views

Ambiguity in Pandas Dataframe “axis” definition

I've been very confused about how python axes are defined, and whether they refer to a DataFrame's rows or columns. Consider the code below: >>> df = pd.DataFrame([[1, 1, 1, 1], [2, 2, 2, ...
0
votes
2answers
23 views

Does numpy.all_close check for shape for the array like elements being compared

Its not clear from the documentation whether numpy.all_close check for shape.
2
votes
1answer
33 views

n-dimensional table lookup: array, dataframe, or dictionary?

I'm trying to find the best way to do n-dimensional table lookups. In this example, there is a dataframe that contains a person's state and the year, and I want to find the relevant tax rate by ...
-1
votes
1answer
24 views

matplotlib won't successfully import anymore

RuntimeError Traceback (most recent call last) RuntimeError: module compiled against API version 9 but this version of numpy is 7 how can i fix this?
1
vote
2answers
33 views

calculating means from csv with python's numpy

I have a 10GB (can't fit in RAM) file of the format: Col1,Col2,Col3,Col4 1,2,3,4 34,256,348, 12,,3,4 So we have columns and missing values and I want to calculate the means of columns 2 and 3. With ...
0
votes
1answer
18 views

How to modify different parts of a numpy array of complex numbers in parallel using python?

How to modify different parts of a numpy array of complex numbers in parallel using python? This question seems to give an answer for numpy array with real coefficients: Is shared readonly data copied ...
2
votes
0answers
38 views

vectorized matrix power and matrix dot using numpy

I want to calculate the power of many 2-D matrices, and would like to do it as fast as possible. I couldn't find a vectorized method to do it. For example: import numpy as np mat_list = ...
1
vote
2answers
29 views

Function returning elements of a multi-dimensonal list in python

I am trying to define a function that returns elements of a multi-dimensional variable according to a nested list of indices. I am working with variables depending on multiple dimensions like, e.g.: ...
0
votes
1answer
18 views

scipy.stats.pearsonr with lists of Decimals?

Trying to run scipy.stats.pearsonr with two lists of Decimal is making scipy unhappy: print type(signals) print type(signals[0]) print type(prices) print type(prices[0]) <type 'list'> ...
1
vote
1answer
17 views

Referencing Data From a 2D Histogram

I have the following code that reads data from a CSV file and creates a 2D histogram: import numpy as np import pandas as pd import matplotlib as mpl import matplotlib.pyplot as plt #Read in CSV ...
2
votes
0answers
30 views

NumPy array acts differently based on origin (np.max() and np.argmax())

I have a function which creates a NumPy array from a data file. I want to then get the maximum value in the array and the index of that value: import numpy as np def dostuff(): # open .txt file ...
3
votes
1answer
22 views

Numpy structured arrays: string type not understood when specifying dtype with a dict

Here's what happens if I initialize a struct array with the same field names and types in different ways: >>> a = np.zeros(2, dtype=[('x','int64'),('y','a')]) >>> a array([(0L, ''), ...
2
votes
1answer
21 views

h5py: slicing dataset without loading into memory

Is it possible to slice an h5py dataset in two subsets without actually loading them into memory? E.g.: dset = h5py.File("/2tbhd/tst.h5py","r") X_train = dset['X'][:N/2] X_test = dset['X'][N/2:-1] ...
0
votes
0answers
20 views

Organizing column and header data with pandas, python

I'm having a go at using Numpy instead of Matlab, but I'm relatively new to Python. My current challenge is importing the data in multiple file in a sensible way so that I can use and plot it. The ...
0
votes
4answers
49 views

Comparing values in two numpy arrays with 'if'

Im fairly new to numpy arrays and have encountered a problem when comparing one array with another. I have two arrays, such that: a = np.array([1,2,3,4,5]) b = np.array([2,4,3,5,2]) I want to do ...
0
votes
1answer
15 views

import function from standard library after importing similarly named function from other library

This is a curiosity. Say I am using IPython interactively, which by default imports from numpy import sum and after that I decide to use sum from the standard library. Say, to do something like ...
1
vote
1answer
26 views

Python loadtxt and genfromtxt truncate strings

I have a 2-column array mixed type array that I need to read in and reshape into a data cube. I've got most of it working, but for some reason both numpy.loadtxt and np.genfromtxt drop everything ...
-1
votes
2answers
39 views

Array formatting with numpy?

I'm trying to create a numpy array for mathematical processing and I can't seem to format my code correctly. I have signals from a numpy array: 'A','B','C','D','E' which I want to be the "headers" or ...
-1
votes
0answers
25 views

Using matplotlib to draw contours on top of a figure (Python)?

I have code for a figure with data for x, y, vx, and vy in txt files: import matplotlib.pyplot as plt import numpy as npy ...
1
vote
1answer
57 views

Trying to Solve Monty Hall in Python

I'm trying to understand this solution of the Monty Hall problem, I understand most of the code, but am stuck on two pieces. Below is the code, but specifically I'm stuck on these two parts ...
2
votes
1answer
10 views

scipy voronoi 3d - not all ridge points are shown

I have been having trouble using scipy's Voronoi function. I have followed the 2d example, however when I performed a similar example in 3d not all the ridge_points are computed. My data is a box of ...
0
votes
1answer
22 views

Install numpy + pandas as dependency in setup.py

Installing numpy + pandas via setuptools as dependency in setup.py does not work for me. It is not about missing dependencies. If I install numpy via pip install numpy and afterwards python setup.py ...
1
vote
2answers
21 views

Find missing values in NumPy array of dtype obj

I'm being driven crazy by a NumPy array of dtype obj with a missing value (in the example below, it is the penultimate value). >> a array([0, 3, 'Braund, Mr. Owen Harris', 'male', 22.0, 1, 0, ...
1
vote
1answer
35 views

Scipy error: numpy.dtype size changed, may indicate binary incompatibility (and associated strange behavior)

I am installing numpy/scipy/scikit-learn on OS X 10.9.4, and am getting errors about "numpy.dtype size changed, may indicate binary incompatibility". Here's what I did to construct the repo: ...
0
votes
2answers
32 views

Appending arrays in numpy

I have a loop that reads through a file until the end is reached. On each pass through the loop, I extract a 1D numpy array. I want to append this array to another numpy array in the 2D direction. ...
-4
votes
1answer
46 views

How would I plot a function f(x,y) (technically a field) as a colour gradient in Pylab?

I am current trying to plot a function f(x,y), which is technically a vector A(r) and a field if I am being nit picky. The plot: I want the plot to be done over an XY graph, where f(x,y) is ...
2
votes
1answer
33 views

Handling computationally intensive tasks in a Django webapp

I have a desktop app that I'm in the process of porting to a Django webapp. The app has some quite computationally intensive parts (using numpy, scipy and pandas, among other libraries). Obviously ...
-3
votes
1answer
44 views

How to get rid of values from Numpy array without loop?

I have a numpy array similar to the following that represents neighbors of each individual (This is first generated by igraph package then converted to numpy array import numpy as np import igraph ...
0
votes
1answer
24 views

Save a numpy matrix

I have a 3D array and I would like to obtain a 2D image along X-Y with the maximum value of z at each point and save it as a numpy array. import numpy as num matrix=num.load('3d') ...
2
votes
2answers
38 views

Parameters of a sigmoid regression in Python + scipy

I have a Python array containing dates representing the number of occurrences of a phenomenon in a particular year. This vector contains 200 different dates repeated a certain number of times each. ...
0
votes
1answer
53 views

Double loops for “concatenation of subarrays in bigger array”

I want to assemble several subarrays in a big array automaticly, "manually" it s that : import numpy as np blank = np.empty([4,4]) A = np.ones([2,2]) B = np.ones([2,2]) * 2 C = np.ones([2,2]) * 3 D ...
0
votes
1answer
31 views

Cython/Numpy - cimport numpy as np fails

I am trying to use cython to code critical part of my code but I have trouble doing to import numpy : Setup.py from distutils.core import setup from distutils.extension import Extension ...
-2
votes
0answers
16 views

Chi Squared Goodness Of Fit Program - Linear/Polynomial Fits Working - Has Exponential Issues

I'm new here and this is my first serious python program I've made to help me carry out fast chi-squared goodness of fit tests using linear, polynomial and exponential models. My models for linear and ...
0
votes
0answers
9 views

PySci ols returns “unsupported operand type(s)”

this is my small program: import csv import ols import numpy def convert(row): return [float(row[0]), float(row[1]), float(row[2]), float(row[3]), float(row[4]), float(row[5]), float(row[7]), ...
2
votes
1answer
52 views

Plotting the means on a plot in matplotlib

I have a dataset consisting of multiple temperature profiles and I want to create a mean temperature profile. In order to do this I figured that if I could calculate the mean at each depth, I could ...
0
votes
1answer
21 views

numpy, Select elements in rows by 1d indexes array

Let we have square array, n*n. For example, n=3 and array is this: arr = array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) And let we have array of indices in the each ROW. For example: ...
0
votes
0answers
46 views

How to calculate 6x6 sudoku solved board pattern?

I wrote a code to calculate 6x6 sudoku solved board pattern in Python. But this code seems not to output all solved board pattern. Because I think there is more pattern. #index of board: #| 0 | 1 | ...