All Questions

25 questions
Filter by
Sorted by
Tagged with
51 views

Efficient ListConvolve over 3d matrix

I'm trying to find an efficient way of applying list convolve to a 3d matrix of 0 and 1, where about 5% of the matrix are 1, but the 1s may either be randomly placed, or grouped in one large ...
629 views

Given: ...
122 views

Fast way to compute a truncated series using Fold

I'm looking at an efficient and fast way to compute the results of a finite summation $$\sum_{i=0}^Mf_ig_i\,.$$ I noticed that simply applying ...
156 views

A Table of Sums, but faster

I'm trying to calculate the following lists a_j and b_j from some predefined values. (this is not code, it's just supposed to be a mathematical expression) ...
2k views

How to map and sum a list fast?

The following takes a lot of memory and is slow: AbsoluteTiming[Total[Map[#^2 &, Range[1, 100000000]]]] I suspect this is because it first calculates and ...
147 views

Modifying codes in a more 'Mathematica' way

I have the following codes: ...
261 views

Alternatives to For/Do Loop to optimize indexing Matrix

I am trying to optimize my code that searches for elements in the rows of matrix that are greater than 0. Then use that position to grab the element from other matrix. I use the do loop to iterate ...
199 views

Counting runs in bits, along with their starts and lengths, in functional style

Here is some code to visualize Project Euler Problem 502. The code scans for runs of bits in the binary representation of an integer, and outputs the beginning position of each run and the length of ...
209 views

How to terminate early a functional computation

Problem description: Given a list $A=\{1,2,0,7,0,-1,2,6,\ldots\}$ and a list $B=\{0,7,0\}$ write a program that determines whether $B$ appears in $A$ or not. Note: the order of $B$'s items does matter....
67 views

Returning functions that are partly evaluated

I have some performance issues when calling Table[{h, Slow1[h, n]}, {n, nlist}, {h, 0.1, 10, 0.5}]; for a given list ...
117 views

Is it possible to sum the results of a Map - Apply?

I am fairly new to functional programming and would like to replace a For[] loop that sums the results over a Dataset. This may be a bit different since the ...
265 views

Functional-programming virus infection

Update: The question may seem too broad, but the answer provided by belisarius responds perfectly to the question, as the use of $ListConvolve$ and $NestList$ meets the desired criteria in in addition ...
74 views

571 views

Choose between Apply and Map

Even though this might be too general question(or not answerable), I want to get some advice here. I apologize in advance if it is not a relevant question. I frequently have to process large list of ...
465 views

How to get “Signature” of each element of “Permutation” output

I need to sum over all possible permutations, multiplied by the Signature of each permutation of a given list of symbols. But, I don't know how to determine the <...
168 views

How to remove recursion, and write it functional and efficient way?

I wish to implement the following recursion efficiently. ...
388 views

Listable on first level [duplicate]

I have some function which take List as input. f[l_List]:=someActions[l] I need apply this function to a list of lists. Now I ...
231 views

Improving the speed of evaluating Table with nested functions

I am a Mathematica novice working with a stack of 1024 x 1024 WatershedComponents (or MorphologicalComponents) label matrices ...
2k views

What is the most efficient way to map a linked list?

In order to work with lists effectively using common recursive patterns from functional programming, it's often most convenient to worked with the "linked list" representation, that looks like this: <...
329 views

About auto-compiling and performance between Do and Fold

I was investigating how Fold could improve performance vs Do. I tested the code ...
184 views

Why is this code in functional style is slower than procedural style?

I know that in Mathematica a functional programming style is often more efficient than procedural style programming using For loops. But the code shown below seems ...
547 views

Variant of the cutting-stock problem in Mathematica

I'm pretty new to Mathematica and am trying to learn to solve problems in a functional way. The problem I was solving was to list the ways in which I could sum elements from a list (with repetitions), ...