# Tag Info

1 vote

### Multiple columns from a single column of data file

If I understand what you seek, then with z = Range for clarity, maybe: ...
1 vote

### Multiple columns from a single column of data file

First save a list of random numbers to a file to create a mock experiment: alist = RandomReal[{0, 1}, 100] Export["C:/alist.txt", alist, "List"] ...
1 vote

### How to replace anti diagonal elements of a matrix

Making use of the method posted by ciao (in an answer to How to zero (or replace) the diagonal of a square matrix?) ...
1 vote

### How to replace anti diagonal elements of a matrix

idm = IdentityMatrix[Length@m] (res = Reverse /@ (m idm) + m (-(Reverse /@ idm ) + 1) ) // MatrixForm \left( \begin{array}{ccccc} 100 & 9 & 3 & 8 &...

### How to replace anti diagonal elements of a matrix

use element-wise operation. keep the diag-matrix and reverse it. anti = mat // Diagonal // (*take diag*) DiagonalMatrix // (*make mat*) Map[Reverse] (*rev it*) {...

### How to replace anti diagonal elements of a matrix

We can subtract the anti-diagonal to remove it and then add the Reverse of diagonal. ...

### How to replace anti diagonal elements of a matrix

From The Procedural Dodo: If you can do it in place (destroying the orginal m), this will be fast: ...

### How to replace anti diagonal elements of a matrix

Using ReplacePart: ...
Accepted

### How to replace anti diagonal elements of a matrix

This is the kind of question that might trigger the "how-many-ways-can-you-do-it" game. I'll kick it off with this: ...

### 'Mapping' the values of a list to variable

Different way: expr1 = a[n] + b[n] stencil = {-1, 0, 1} f[ex_, sten_] := Sum[Map[# + tp &, ex, {2}] /. tp -> sten[[i]], {i, 1, Length[sten]}] Then, ...
Accepted

### Convert List to Matrix

Clear["Global`*"] (mat = RandomInteger[200, {3, 3}]) // MatrixForm Note that the MatrixForm wrapper is isolated ...
Accepted

### How to efficiently rearrange elements in big data file?

The easiest answer is to use Transpose ...

### Selecting terms from a list based on certain pattern

n = 3; run = n - (-1) + 1; sel = Flatten@ Normal@SparseArray[{Band[{1, 2}] -> 1, {run, _} -> 1}, {run, run}]; res = Pick[myTab, sel, 1] {{-1, 0}, {0, 1},...
Accepted

### Selecting terms from a list based on certain pattern

Using patterns and Cases: ...
1 vote
Accepted

### 2D Scatter plot with z-value used for PlotLegends

Using Graphics ...
1 vote

### Generating Lyndon words modulo mirroring operation and substituion

Here is a bit of code, in case anyone wants to improve on this. Perhaps it also helps clarify what the exact statement of interest is. All code below is completely ad-hoc. (Note that unlike the answer ...
1 vote

### Generating Lyndon words modulo mirroring operation and substituion

In order to start somewhere, here is my code to generate Lyndon words. First, the following function returns the number of words for a particular n (from oeis.org): ...
1 vote
Accepted

### Table mix with If function

I assume you want something like the following: ...
1 vote

### Write the result of expression to a list

Using Array : Array[2 Cos[# \[Pi]/3] &, 100] also delivers the same output. If you don't want to use pure functions or if a ...

...

### Write the result of expression to a list

You can take advantage of the Listable attribute of the trigonometric functions (ie the fact that they automatically thread over lists, to produce a list of results)...
Accepted

### Write the result of expression to a list

As @LouisB comments, using Table: ...

### Unexpected behaviour of Condition with Cases/MatchQ?

Condition[a, b] is pattern that matches a provided b is ...
1 vote
Accepted

### Divide string into a sublist of sentence with the maximum number of character

Okay, reading your updated question, maybe this is what you want: Starting with some sample data to test with: ...

### Divide string into a sublist of sentence with the maximum number of character

Let's get some text from Charles Dicken's Oliver Twist. Define: ...

### Divide string into a sublist of sentence with the maximum number of character

Starting with your data: string = "This is the first sentence. This is the second sentence. This is the third sentence." There are two (at least :) ) ...

### Replacing large numbers

Using Condition: l /. x_Integer /; x > 10^6 -> 0 (*{{1, 2, 3}, {4, 0, 5}}*) Or in the same way: ...

### Replacing large numbers

You could use 3-arg Clip: Clip[l, {-Infinity, 10^10}, {0, 0}] {{1, 2, 3}, {4, 0, 5}} where I used ...

### Replacing large numbers

l = {{1, 2, 3}, {4, 10^(16), 5}} Define a high, low threshold as well as a substitute. thlow = 2; thhi = 3; subst = 11; Find ...

### Replacing large numbers

I'm assuming you want something generalizable. Let's say your threshold is 10^10, then something like this: Map[If[# > 10^10, 0, #] &, l, {2}] You could ...

### How to generate a list of random numbers with conditional statements

SeedRandom; rlist = RandomReal[{1, 20}, 10]; {16.5304, 3.11697, 16.001, 4.56826, 5.58586, 2.24904, 11.3027, 5.39194, 8.52412, 14.309} Using ...

### How to generate a list of random numbers with conditional statements

One way "to generate a list of numbers with certain conditions" is to create an ImplicitRegion based on your constraints, and then use ...
Accepted

### What is the best method to search pattern for 2D list?

You could use ArrayFilter: ...

### What is the best method to search pattern for 2D list?

another array-based method: ...

### What is the best method to search pattern for 2D list?

I am sure there are many ways to do it, but here is my take: ...
1 vote

### How can I multiply only a few columns of a table by some number in a compact way?

Building a MultiplyByPosition function: ...

### Simple, fast re-defining a part of 2D list

Another option is to use ReplacePart ...

...

### Piecewise Functions from List of Functions

Hooray, I figured it out! Only took 5 hours of struggling for this... ...

### From list shown below - highlight in BOLD the pair with the highest value

You can highlight the largest case with MapAt: MapAt[Style[#, Bold] &, list, OrderingBy[list, Last, -1]] In the last ...
1 vote

### How can I multiply only a few columns of a table by some number in a compact way?

MapAt[a*#&,tab,{{All,2},{All,5}}]
1 vote
Accepted

### Why does my simple string function fail to grab the only element in a List?

I recommend handling the String vs. List arguments with alternative definitions of your function. That would simplify your work, ...

### How can I multiply only a few columns of a table by some number in a compact way?

Using the Dot product: tab.DiagonalMatrix[{1,2,1,1,2,1}] Or, if there are a lot of columns: Edit Lucas Lang suggested a neat ...

### How can I multiply only a few columns of a table by some number in a compact way?

a = 2; k = 2; m = 5; Using direct multiplication: ...

### How can I multiply only a few columns of a table by some number in a compact way?

Another option could be a*tab[[All, {2, 5}]] Which will multiply columns 2 and 5 by a. To replace the original matrix just do <...