Questions tagged [numpy]

NumPy is the fundamental package for scientific computing with Python.

Filter by
Sorted by
Tagged with
2
votes
2answers
2k views

vectorizing a non-trivial function in numpy

I have a 2d numpy array, with shape (100,3) a = np.random((100,3)) and I want to call a function ...
4
votes
2answers
7k views

Consistent handling of division by zero in numpy array

I want to populate a numpy array with values from the smooth bump function f(x) = exp ( - 1 / (1 - x^2) ) if |x| < 1, f(x) = 0 otherwise Currently I ...
5
votes
1answer
3k views

Logistic regression with Python

I am trying to code up logistic regression in Python using the SciPy fmin_bfgs function, but am running into some issues. I wrote functions for the logistic (...
2
votes
1answer
265 views

Reshape and Index (State) Products in Numpy

Consider the following: I start with a $2\times 2$ matrix $W_{ij}$. I then take this $W$ matrix and make a new tensor, $T$, by doing the following: $$ T_{ijkl}=\sum_{a}W_{ai}W_{aj}W_{ak}W_{al} $$ ...
27
votes
5answers
17k views

Permute a matrix in-place in numpy

I want to modify a dense square transition matrix in-place by changing the order of several of its rows and columns, using python's numpy library. Mathematically this corresponds to pre-multiplying ...
2
votes
1answer
1k views

f2py: error f90 not supported by GnuFCompiler needed for source_file.f90

I'm trying to install a Python package that relies on extensions built from Fortran 90 using f2py, but I get the following error: ...
3
votes
1answer
819 views

32bit/64bit issue when working with Numpy and petsc4py

When indexing PETSc.Mat A with an array c ( numpy.ndarray with ...
4
votes
1answer
1k views

Python syntax for MATLAB/Octave colon operator a:dx:b

I am trying to rewrite some MATLAB/Octave code in Python, and I don't know what would be the nicest or most intuitive way of writing ...

1 2 3