All Questions

Filter by
Sorted by
Tagged with
0
votes
1answer
40 views

Sequence of functions iteratively defined

I would like to iteratively define a vector of functions (called copies in the following) depending on a parameter s and a ...
1
vote
1answer
30 views

Cut a list into two sublists containing alternating chunks? [duplicate]

Consider a list such as list=Range[20] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 } I would like to have a function (e.g. ...
6
votes
2answers
140 views

Collect data points in a list into weekly groups?

Consider data of a format such as ...
0
votes
0answers
44 views

Function works outside For loop but not inside, and loop fails spectacularly

I'm building two lists, each to carry a different representation of the same set of objects. One list, list2, is constructed first; then the second list, ...
0
votes
1answer
34 views

Defining a function that modifies a list [closed]

I have the a list A and I want to define a function f that takes out the $i$-th element from the list ...
4
votes
3answers
169 views

Finding the index of an element to be inserted in a sorted list

I have a sorted list with no duplicates: L = {1, 2, 5, 7, 8} Given an integer n, I want to find the index of ...
7
votes
5answers
280 views

How to generate all commutative pairings of list elements?

Given a list with an even number of elements, e.g. list = RandomSample[Array[e, 20]]; how can one generate a list of all different commutative pairings of the ...
10
votes
4answers
184 views

Efficiently merge lists chronologically without duplicates?

Prepare some dummy data to investigate: ...
0
votes
1answer
38 views

Tracking back a variable corresponding to an output

I have a function: ...
14
votes
2answers
716 views

Flatten not working

I am trying to modify some code proposed here Part assignment is not a symbol and I cannot manage to make Flatten work. I write ...
0
votes
0answers
47 views

Why is this iterative process with matrix calculation so slow?

I am trying something similar to the following code with Ntime as large as 100 or so. Now it's very slow as shown by the Ntime=3 ...
3
votes
3answers
112 views

Find non-case sensitive string in a mixed list of elements?

Consider an example list with mixed element types, e.g.: list = { 1.234 , a[2] , {"Abc" , 4/5} , "acb" }; I would like to have a function that finds the position ...
1
vote
1answer
61 views

Nested Do loops with externally defined iterators [closed]

I want to be able to define a set of iterators for nested Do loops, such as ...
4
votes
2answers
180 views

Simulating ndgrid function of MATLAB

I know that there has been an answer on meshgrid function of MATLAB. For functions involving more than 3 variables, this function does not work. In MATLAB, the ...
5
votes
5answers
351 views

Replacing the Zeros of One List by the (i-1)th Element of Another List

My goal is to replace the zeros of one list with the (i-1)th element of a second list. For example, if list1 = {0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0} and <...
4
votes
2answers
69 views

How to make FoldListIndexed ie FoldList with an index or iterator?

Is there a functional or inbuilt way to add an index to FoldList? i.e.: FoldListIndex[f,x,{a,b,...}] gives ...
3
votes
2answers
106 views

Truncate a set of lists until a subset of entries matches?

Consider lists of vectors of elements like ...
0
votes
1answer
29 views

Cut graph at a given edge and return remaining subgraphs?

I would like to have a function that removes an edge from a graph and returns all remaining graphs after the operation. For example for a graph like ...
6
votes
4answers
350 views

Iteratively strip off simply connected edges in graph?

Consider a set of edges composing a directed graph. For example: ...
6
votes
2answers
143 views

Select connected subsets of integer pairs?

Given a list of integer pairs such as list = { {1,2},{1,3},{2,5},{1,5},{6,7},{6,9},{4,6} }; What is a quick way to separate the pairs into groups in which every ...
3
votes
2answers
81 views

Converting a free variable in a pure function into a parameter that can be varied under iteration

Here I am going, as a matter of illustration, make a large string list: l = Characters[WordList[]]; l = Table[DeleteDuplicates[l[[i]]], {i, Length[l]}]; This ...
4
votes
1answer
123 views

Jaro distance in MMA

I'm trying to program Jaro distance as requested by this page I've done the following code that works well for the next two pairs ("MARTHA", "MARHTA") and ("DIXON", "DICKSONX") but when I try with ("...
2
votes
1answer
166 views

How to calculate linear conflicts on a board?

Thanks to your help to solve previous problems, I have been able to advance in the learning of mathematica. It seems that this project to make a solver for the 8-puzzle has surpassed my abilities in ...
4
votes
5answers
296 views

How to build these functions without nested For loops?

I am trying to solve the 8-puzzle using two heuristics, which are: Pieces out of place and Distance Manhattan. After consulting several websites for example see and some books, I'm with some doubts, ...
0
votes
0answers
36 views

Having Trouble with CountryData [EDITED]

I have a list which I call by countryExportPartners = Table[l = CountryData[][[n]]; {l, CountryData[l, "ExportPartners"]}, {n, 1, Length[CountryData[]]}] I ...
1
vote
1answer
47 views

function over list with condition

For a fake function like: fun[x_] := x^0/x!; and list: list={0,0,0.1,0.2,0.9,0.8,0,0}; It will get error in this way cause ...
1
vote
1answer
64 views

Plot of a data list evaluated with other function [closed]

I want to evaluate a function of "two" variables using some data points (x,y(x)) (but one of them is related to the other) that I have made with the function Table. ...
6
votes
2answers
104 views

Efficient way to partition list of expressions based on its contents

I have a list of polynomials polys linear in a set of variables vars. How do I partition the list based on successive dependence ...
0
votes
1answer
49 views

Separate list elements into groups of two in all possible ways? [duplicate]

Consider a list with an even number of elements, e.g. list = {1,2,3,4}; I would like to have a function fun that produces all ...
1
vote
0answers
41 views

How to apply a recursive function to a list [closed]

With a list of parameters list={a,b,c,d,e} How can I apply a function f to obtain ...
11
votes
9answers
1k views

Number of sign flips in list?

Given a list of signs: list={1,1,-1,1,-1,-1,1,1,1,-1}; how to most conveniently and quickly determine the number of sign flips in the sequence? I have this ad-...
1
vote
1answer
115 views

Building a matrix function one element at a time

I would like to define a function which produces an $N\times N$ matrix where each element is a function of the input values ($N$ is a fixed constant). However, each element of the function needs to be ...
1
vote
2answers
66 views

Create matrix from combinational arrangement of vectors

I am just trying to produce a short hand code which shall do the following: I have a function of 2 vectors $f(\vec{v_1},\vec{v_2})$ f=#1^2+#2^2-#3-#4&; and ...
3
votes
1answer
135 views

Tower of Hanoi list of disks on the rods

I'm currently trying to finish a program that outputs the "radius" of each disk on each rod in lists. I currently wrote this program: ...
3
votes
2answers
124 views

Listwise “summation”, replacing empty lists with non-empty ones and ignoring “sum” of non-empty lists

Given two lists of equal length, l1 and l2, both consisting of sublists that are either empty or non-empty - but corresponding ...
9
votes
1answer
796 views

What is the elegant way of applying function to two lists?

I am interested in finding the most concise elegant way of doing the following: We have a function fun[x1,x2] and two lists: ...
5
votes
3answers
147 views

Generate all dihedral transformations of a matrix?

Given a matrix, e.g. matrix = Table[a[i, j], {i, 1, 3}, {j, 1, 3}]; I would like to have a function that takes matrix as ...
1
vote
1answer
112 views

Finding total distance between a point and all points in a list?

I am looking for the total distance from each point in a list to all points in a another. Specifically from each point in Asubopt to every point in ...
1
vote
1answer
36 views

How to use Apply and Map properly in this situation? [duplicate]

So this does what I want: #1 <> #2 &["♠", "A"] ♠A The output is fine. How do I quickly apply this to the list ...
1
vote
0answers
54 views

Efficiently transform sequentially generated integer matrices into boolean matrices

Assume you have a list of 5 numbers, eg L = {14, 7, 11, 14, 0};. Now, what you want to do with this list, is to transform each entry into eg a binary list, using <...
2
votes
2answers
264 views

How to append functions to a list of functions?

[This question has been rewritten] To simple down my last question, I think this example will be more clear. Suppose I have this list of functions list1[a] and append them to another list of ...
2
votes
7answers
489 views

Converting integer to a triangular array

I've been trying to write a function toTriangle which converts a given integer to a triangular array. For example: ...
2
votes
2answers
56 views

Condition on the index of an element $a_{i,j}$

This question may seem to be easy. But I did not find the right way after several attempts I need to put a condition in general for $a_{i,j}$ ,If the i is bigger ...
7
votes
4answers
255 views

Group by Lengths of Lists [duplicate]

Let’s say, we have a list of lists: Table[0, {30}, RandomInteger[{1, 5}]] which might look like this ...
2
votes
2answers
81 views

Cyclically sort lists with some repeated elements? [duplicate]

This is a continuation of this question. In the previous question we got a routine that can take two cyclically equivalent lists and determine their equivalence if all the elements in each list are ...
0
votes
1answer
342 views

Depth function that counts number of nested lists

I'm looking for a function that gives the depth of nested lists in an expression. I do not want to include contributions from things like f[1]. Depth does do this. ...
10
votes
7answers
703 views

intersection between two 2D arrays with labeled data is slow

Here is how to Generate data the function is below with two images to generate data img1 img2 ...
0
votes
0answers
73 views

Extracting Data from For Loop

I want to add phases in for loop and after adding a new phase I want to export this data? How can I do this? Can you show me where I do wrong? ...
3
votes
2answers
192 views

A function that accepts a list of pairs and adds new pairs that are the averages of the neighbouring pair values

Probably a duplicate, but it isn't easy browsing through list-related questions. I am looking for an elegant way to construct a function that accepts a list of pairs, for example ...
34
votes
3answers
770 views

Can we intelligently control evaluation in Thread?

This is a bid at creating a canonical Q&A. Many questions have been asked that come down to the fact that Thread evaluates its first argument before threading ...