c,multithreading,cuda,scientific-computing,nvcc

Note that in the entirety of your writeup, I do not see a question being explicitly asked, therefore I am responding to: I am looking forward to learning what is going on here. You have a race condition on d_u. by your own statement: •in order to keep the blocks...

python,optimization,numpy,pandas,scientific-computing

Numpy has repeat() for that type of thing. Given two arrays A = np.array([100.4,98.3,88.5]) B = np.array([7,3,10]) np.repeat(A,B) will give you array([ 100.4, 100.4, 100.4, 100.4, 100.4, 100.4, 100.4, 98.3, 98.3, 98.3, 88.5, 88.5, 88.5, 88.5, 88.5, 88.5, 88.5, 88.5, 88.5, 88.5]) ...

caching,optimization,computer-architecture,scientific-computing,supercomputers

Memristors will be used as a replacement for SRAM cells. Even though they might increase the memory density/area and bring along improvements in power efficiency, I do not see them changing the concept of data locality as that is an abstract concept. Yes, it will lead to an increase in...

optimization,mathematical-optimization,linear-programming,scientific-computing,integer-programming

Edit: Setting Variable2 equal to min or max of Variable1 and Parameter. min(Parameter,Variable1): If you are sure that Variable2 "wants" to be small in the objective function, then you just need to require Variable2 to be less than or equal to both Parameter and Variable1: Variable2 <= Variable1 Variable2 <=...

optimization,mathematical-optimization,linear-programming,scientific-computing,integer-programming

First create a binary variable that equals 1 if Variable1 > 0 and 0 if Variable1 < 0: Variable1 <= UB * BinaryVar LB * (1 - BinaryVar) <= Variable1 (If Variable1 > 0, then BinaryVar must equal 1. If Variable1 < 0, then BinaryVar must equal 0. Note that...

lapack,hpc,scientific-computing,intel-mkl

The function LAPACKE_dptsv() corresponds to the lapack function dptsv(), which does not feature the switch between LAPACK_ROW_MAJOR and LAPACK_COL_MAJOR. dptsv() is implemented for column-major ordering, corresponding to matrices in Fortran, while most of C matrices are row-major. So LAPACKE_dptsv(LAPACK_ROW_MAJOR,...) performs the following steps : transpose the right-end side b call...

python,performance,numpy,scientific-computing,numba

This does almost the same thing as your (excellent!) self-answer, but with a bit less rigamarole. It seems marginally faster on my machine as well -- about 30ms based on a cursory test. def apply_indexed_fast(array, func_indices, func_table): func_argsort = func_indices.argsort() func_ranges = list(np.searchsorted(func_indices[func_argsort], range(len(func_table)))) func_ranges.append(None) out = np.zeros_like(array) for f,...

c++,matlab,math,precision,scientific-computing

Converting to double in C++ inside the computation solves the difference problem. We reach a very satisfactory match after converting to double.

bash,image-processing,parallel-processing,scientific-computing

I regularly process 65,000+ images per day and I just about always use GNU Parallel - see here and here. I wouldn't bother parallelising C code! It allows you to specify how many jobs to run in parallel, or just use the default of one job per CPU core. It...

python,matplotlib,scientific-computing,spyder

This has to do with matplotlib, not Spyder. Placing the location of a figure explicitly appears to be one of those things for which there's really just workarounds ... see the answers to the question here. That's an old question, but I'm not sure there's been change since then (any...

python,python-2.7,scipy,enthought,scientific-computing

There is an iteration in the lambertw code. Apparently it is not converging when given a large argument. (And as @unutbu's answer shows, whether or not it converges appears to depend on your configuration.) Here's an alternative that works for (scalar) positive real arguments up to the maximum floating point...

python,numpy,physics,scientific-computing,differential-equations

I don't have the time to study your solution in detail, but it seems that you are solving the partial differential equation with a forward Euler scheme. This is pretty easy to implement, as you show, but this can become numerical instable if your timestep is too small. Your only...

python,matplotlib,ipython,visualization,scientific-computing

A: This can be done at a cost of changed matplotlib Renderer Currently, this cannot be done for the IPython "inline" graphs, however, if you opt to change a Renderer part of the matplotlib framework, to another one, the limitation of a singleton call of the .show() method does not...

Copying the script can be done with shutil.copy(). But you should consider keeping your script under revision control. That enables you to retain a revision history. E.g. I keep my scripts under revision control with git. In Python files I tend to keep a version string like this; __version__ =...

python,numpy,pandas,scientific-computing

You can use melt to convert a DataFrame from wide format to long format: import pandas as pd df = pd.DataFrame({'date': ['2012-12-31', '2012-12-30', '2012-12-29', '2012-12-28', '2012-12-27'], 'hour1': [9.18, 13.91, 12.97, 22.01, 11.44], 'hour2': [-0.1, 0.09, 11.82, 16.04, 0.07]}) print pd.melt(df, id_vars=['date'], value_vars=['hour1', 'hour2'], var_name='hour', value_name='price') Output: date hour price 0...

python,numpy,rounding,scientific-computing

import math def round_on_error(value, error): significant_digits = 10**math.floor(math.log(error, 10)) return value // significant_digits * significant_digits Example: >>> errors = [0.2,1.123,1.0, 123123.1233215,0.123123123768] >>> values = [12.3453,123123321.4321432, 0.000321 ,321321.986123612361236,0.00001233214 ] >>> map(round_on_error, values, errors) [12.3, 123123321.0, 0.0, 300000.0, 0.0] And if you want to keep a value that is inferior to its...

python,arrays,performance,numpy,scientific-computing

Here are a few methods you could try: using vstack and transpose: p = numpy.vstack((x, y, z)).T using concatenate and reshape p = numpy.concatenate((x, y, z)).reshape((3, len(x))).T allocating a new array and using put p = numpy.empty((len(x), 3)) for i, a in enumerate((x, y, z)): p[:,i] = a Along with...

perl,tree,bioinformatics,scientific-computing,bioperl

This code produces SVG output on STDOUT (I'm not qualified to comment on whether the correct nodes are displayed): use v5.16; # sets strict and warnings use Bio::Phylo::Forest; use Bio::Phylo::Treedrawer; my $string = '(B:6.0,(A:5.0,C:3.0,E:4.0):5.0,D:11.0);'; my $forest = Bio::Phylo::IO->parse( -format => 'newick', -string => $string )->first; my $treedrawer = Bio::Phylo::Treedrawer->new( -width...

python,sql,postgresql,psycopg2,scientific-computing

When you add time to a date the result is a timestamp which you can cast to time: select (current_date + market_data_time)::time; ...

matlab,root,numerical,scientific-computing

You suppose to add up terms so replace minus in this line: x = x - (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3)))); To a plus: x = x + (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3)))); To get a desired result of 2.987 for x. Also remove x before the end of the loop. ...