Tagged Questions
3
votes
0answers
71 views
vectorize a function operated on subarray of a ndarray
I have a function acted on each 2D slices of a 3D array. How to vectorize the function to avoid loop to improve the performace? For example:
def interp_2d(x0,y0,z0,x1,y1):
# x0, y0 and z0 are 2D ...
3
votes
0answers
93 views
Keeping a numpy ndarray subclass as the return value during a transformation. Safe to set __array_priority__?
I'm trying to subclass numpy's ndarray class, and have had some luck. The behavior that I would like is nearly exactly the same as the example given in the documentation. I want to add a parameter ...
2
votes
0answers
216 views
Numpy high precision
I am using numpy and pyfits to manipulate spectra and I require high precision (something like 8-10 decimal places on a value which might go as high as 10^12). For that the data type "decimal" would ...
2
votes
0answers
549 views
output operand requires a reduction, but reduction is not enabled Python
import numpy as np
from numpy.linalg import solve,norm,cond,inv,pinv
import math
import matplotlib.pyplot as plt
from scipy.linalg import toeplitz
from numpy.random import rand
c = np.zeros(512)
c[0] ...
2
votes
0answers
277 views
Inverting a numpy boolean array using ~
Can I use ~A to invert a numpy array of booleans, instead of the rather awkward functions np.logical_and() and np.invert()? Indeed, ~ seems to work fine, but I can't find it in any nympy reference ...
1
vote
0answers
114 views
2D Numpy Array Beginner troubles
my issues is with trying to work with arrays that for each elements is a tuple of 2 values.
specifically the problem is to generate a random 2-dimensional walk of 200 (but for testing say 2) steps ...
1
vote
0answers
141 views
Multiplying Numpy 3D arrays by 1D arrays
I am trying to multiply a 3D array by a 1D array, such that each 2D array along the 3rd (depth: d) dimension is calculated like:
1D_array[d]*2D_array
And I end up with an array that looks like, say:
...
1
vote
0answers
133 views
Reading file in Fortran-90 written out by Python f.write()
So someone wrote this code which outputs x,y,z positions of some particles.
if rs.contains_block(file+'.hdf5',"POS ",parttype=1):
d1 = rs.read_block(file, "POS ",parttype=1,verbose=False)
...
1
vote
0answers
187 views
search in a pytables array
I have a multidimensional array stored in pytables.
how do I perform a search on it?
For example: I like to do a search to return a dimension of the array in which the sum of all values of this ...
1
vote
0answers
224 views
Python Memory Use With Large Array Computation
I'm working with large arrays (900, 1000, 10,000) and I need to do simple computations (multiply, divide, etc.). However, I am receiving memory errors. Is there a way to do the following more ...
1
vote
0answers
507 views
masked arrays in numpy error
I input a file using genfromtxt and some of the values are missing so I generate a masked array. When I try to index some of the values of the records of the masked array I get an error which I ...
0
votes
0answers
58 views
porting a function from matlab to python
I am trying to port the following Function from matlab to python:
function J = do_localmax(octave, thresh,smin)
[N,M,S]=size(octave);
nb=1;
k=0.0002;
J = [];
for s=2:S-1
for j=20:M-20
for ...
0
votes
0answers
23 views
What IS a .fits file, as in, what is a .fits array?
I'm basically trying to plot some images based on a given set of parameters of a .fits file. However, this made me curious: what IS a .fits array? When I type in img[2400,3456] or some random values ...
0
votes
0answers
43 views
“truth value of an array” Error : Where is this array?
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
I know this error means one of my truth value isn't a truth value, but how is it ...
0
votes
0answers
23 views
covert the pairwise data to a matrix
I have a similar question to the following poster:
In Python: create a table to visualize pairwise data
but my data missed lots of pairwise information.
so if I use a similar implementation as in ...