Hello,
I am new to c, and the following is giving me some grief:
int i,j,ll,k;
double ddim,ddip,ddjm,ddjp,ddlm,ddlp;
for(i=1; i<(mx-1); i++){
for(j=1; j<(my-1); j++){
for(ll=1; ll<(mz-1); ll++){
ddim=0.5*k
ddip=0.5*k
ddjm=0.5*k
ddjp=0.5*k
ddlm=0.5*k
ddlp=0.5*k
Wijl(i,j,ll) = ((1.0/h_x)*(ddip) \
((1.0/h_x)*(ddim)) \
...
Is there an efficient way to know how many elements are in an iterator in Python, in general, without iterating through each and counting?
thanks.
...
I have a program that contains a large number of objects, many of them Numpy arrays. My program is swapping miserably, and I'm trying to reduce the memory usage, because it actually can't finis on my system with the current memory requirements.
I am looking for a nice profiler that would allow me to check the amount of memory consumed b...
Hello!
I am trying to do a fit to a given function using Scipy. Scipy.optimize.leastsq needs a vectorized function as one of the input parameters.
This all works fine, but now I have a more complicated function which is not vectorized automatically by Scipy/Numpy.
def f1(a, parameters):
b, c = parameters
result = scipy.integr...
numpy.vectorize takes a function f:a->b and turns it into g:a[]->b[].
This works fine when a and b are scalars, but I can't think of a reason why it wouldn't work with b as an ndarray or list, i.e. f:a->b[] and g:a[]->b[][]
For example:
import numpy as np
def f(x): return np.array([1,1,1,1,1], dtype=np.float32) * x
g = np.vectorize(f,...
hi is there a build'in function of python that does on python.array what argsort() does on a numpy.array?
...
I would like to create a two dimensional numpy array of arrays that has a different number of elements on each row.
Trying
cells = numpy.array([[0,1,2,3], [2,3,4]])
gives an error
ValueError: setting an array element with a sequence.
...
If I have an array like
a = np.array([2, 3, -1, -4, 3])
I want to set all the negative elements to zero: [2, 3, 0, 0, 3]. How to do it with numpy without an explicit for? I need to use the modified a in a computation, for example
c = a * b
where b is another array with the same length of the original a
Conclusion
import numpy as ...
I have a Python program that processes fairly large NumPy arrays (in the hundreds of megabytes), which are stored on disk in pickle files (one ~100MB array per file). When I want to run a query on the data I load the entire array, via pickle, and then perform the query (so that from the perspective of the Python program the entire array...
Hi all,
I am just getting to know numpy, and I am impressed by its claims of C-like efficiency with memory access in its ndarrays. I wanted to see the differences between these and pythonic lists for myself, so I ran a quick timing test, performing a few of the same simple tasks with numpy without it. Numpy outclassed regular lists by a...
I have a very large numpy array (containing up to a million elements) like the one below:
[ 0 1 6 5 1 2 7 6 2 3 8 7 3 4 9 8 5 6 11 10 6 7 12 11 7
8 13 12 8 9 14 13 10 11 16 15 11 12 17 16 12 13 18 17 13 14 19 18 15 16
21 20 16 17 22 21 17 18 23 22 18 19 24 23]
and a small dictionary map for replacing some of t...
Hey all,
I'm trying to get a better grip on numpy arrays, so I have a sample question to ask about them:
Say I have a numpy array called a. I want to perform an operation on a that increments all the values inside it that are less than 0 and leaves the rest alone. for example, if I had:
a = np.array([1,2,3,-1,-2,-3])
I would want to...
Hi,
I just am having a problem with NumPy dtypes. Essentially I'm trying to create a table that looks like the following (and then save it using rec2csv):
name1 name2 name3 . . .
name1 # # #
name2 # # #
name2 # # #
.
.
.
The matrix (numerical array in the center), is already computed bef...
I know how to use numpy.savetxt to write an array to a file. How can I write multiple arrays to the same file?
Essentially I want to do math to a column of numbers, and then replace the old column with the modified numbers. I read the easiest way to do this is to write a new file completely, put the modified numbers in, and just 'copy...
Hi,
It seems strange to me that np.corrcoef returns a matrix.
correlation1 = corrcoef(Strategy1Returns,Strategy2Returns)
[[ 1. -0.99598935]
[-0.99598935 1. ]]
Does anyone know why this is the case and whether it is possible to return just one value in the classical sense?
...
Hello all,
I need to take a csv file and import this data into a multi-dimensional array in python, but I am not sure how to strip the 'None' values out of the array after I have appended my data to the empty array.
I first created a structure like this:
storecoeffs = numpy.empty((5,11), dtype='object')
This returns an 5 row by 11 ...
Hi all,
I am trying to adapt the underlying structure of plotting code (matplotlib) that is updated on a timer to go from using Python lists for the plot data to using numpy arrays. I want to be able to lower the time step for the plot as much as possible, and since the data may get up into the thousands of points, I start to lose valua...
I came across a line of code using Python's numpy that looked like this:
~array([0,1,2,3,4,5,4,3,2,1,0,-1,-2])
And it gave the output:
array([-1, -2, -3, -4, -5, -6, -5, -4, -3, -2, -1, 0, 1])
Does the unary operator (~) take an array and apply A -> -(A+1)
If so, whats the point?
...
Hi, I have a set of data and I want to compare which line describes it the best (polynomes of different orders, exponential or logarithmic).
I use Python and Numpy and for polynomial fitting there is a function polyfit(). But I found no such functions for exponential and logarithmic fitting.
Are there any? Or how to solve it otherwise...
I've been trying for hours to get this simple script working, but nothing I do seems to help. It's a slight modification of the most basic animated plot sample code from the Matplotlib website, that should just show a few frames of noise (I have the same issue with the unmodified code from their website BTW).
On my computer with the TkA...