All Questions

Filter by
Sorted by
Tagged with
2
votes
2answers
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 ...
6
votes
2answers
629 views

How can I find a more efficient solution to mapping characters to digits?

Given: ...
4
votes
1answer
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 ...
0
votes
0answers
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) ...
18
votes
7answers
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 ...
0
votes
2answers
147 views

Modifying codes in a more 'Mathematica' way

I have the following codes: ...
3
votes
1answer
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 ...
4
votes
3answers
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 ...
7
votes
1answer
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....
0
votes
1answer
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 ...
0
votes
2answers
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 ...
5
votes
1answer
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 ...
2
votes
1answer
74 views

Let's do this list-rearrangement prettier [duplicate]

Suppose that i have a list in this format= $list=\{ \{a,obj1 \} ,\{c,obj2 \}, \{a,obj3 \}, \{b,obj4 \} \dots\}$ I want to construct a new list in this way: $ newlist= \{ \{ \{a,obj1\} , \{a,obj3\} ....
3
votes
3answers
556 views

fastest way to perform the following summation

I have a vector $A$ with components $A_{i}$, and two matrices $X$ and $Y$ with components $X_{ij}$, and $Y_{ij}$ respectively. What is the fastest way of performing the following summation $$A_{i}A_{...
13
votes
2answers
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 ...
7
votes
3answers
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 <...
3
votes
1answer
168 views

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

I wish to implement the following recursion efficiently. ...
4
votes
1answer
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 ...
0
votes
0answers
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 ...
15
votes
3answers
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: <...
4
votes
2answers
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 ...
4
votes
1answer
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 ...
6
votes
2answers
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), ...
11
votes
4answers
608 views

How to write this without For loop

Suppose I have a few lists of numbers and want to exponentiate element-wise, then sum up everything into a polynomial. For example, if I have ...
0
votes
1answer
400 views

How can I improve my code with efficient mathematica built-in functions?

I have written a module for my assignment like below. V[n + 1] = rk[x[n], y[n] ,z[n], V[n]]; vs = V[n].V[n+1]; V[n + 1] = I want to modify it with efficient ...