Ali Hashmi
• Member for 6 years, 10 months
• Last seen this week

As partly mentioned in this: Add delay to the final frame of a GIF? we can use "AnimationRepetitions" -> ∞ to loop a GIF indefinitely: Export["C:\\Users\\Ali Hashmi\\Desktop\\test.gif", gif, "...

I have somewhat mixed corey's and nikie's approach (check their posts) to arrive at a somewhat reasonable segmentation. Kudos to them. img2 = ImageAdjust@RidgeFilter[img, 5] // GaussianFilter[#, 8] &...

since the result of the new computation depends on the previous one we can use NestList NestList[N@({0, 0, 0.5} + RotationMatrix[45 Degree, {0, 0, 1}].Transpose[#])\[Transpose] &, n01, 18]

Cases[Range[-75, 100], _?(Positive[#] && PrimeQ[#] &)] (* or *) Cases[Range[-75, 100], _?(Apply[And, Composition[Positive[#], PrimeQ[#]]] &)] (* which is the same as the one below*) ...

Using the straightforward way GroupBy Normal@GroupBy[{{2, 3} -> 1, {1, 5} -> 1, {1, 1} -> 2, {2, 2} -> 2}, Last -> First] (* {1 -> {{2, 3}, {1, 5}}, 2 -> {{1, 1}, {2, 2}}} *) ...

list = {{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}; DeleteCases[ list , {0 ..}] (* {{12, 1, 23, 4}, {34, 67, 5, 60}} *) (* this also results in the same answer *) Cases[ list , ...

For really big list or a rectangular matrix I would suggest the following approaches: list = RandomInteger[20, 1000000]; f1[list_,num_] := SparseArray[UnitStep[list-(num + 1)]]["NonzeroPositions"]; ...

The code below has been fixed and is now working. It is based on RNSL model (a modified version of Nagel Schreckenberg model that works for the case of two lanes). Clear@func; With[{maxbound = 100, ...

you can use PixelValuePositions Show[image, MapThread[Graphics[{#2, Point@RandomSample[PixelValuePositions[image, #1], 2000]}] &, {{0, 1}, {Red, Blue}}]] of course there are some outlying ...

a /: Except[TagUnset, _][___, a, ___] := (Print["a fired"]; Null); f[a] (* a fired *) (* As we can see below, usage of ClearAll does not work *) ClearAll[a] (* a fired *) (* now removing the ...

on suggestion of @george2079 checkInteger[num_] := (# === 0. || # === 0) &@FractionalPart[num]

Mean@Cases[{1, 2, 3, NaN, 2}, Except[NaN]] (* 2 *) Mean@DeleteCases[{1, 2, 3, NaN, 2}, NaN] (* 2 *)

This gives all paths and not just the shortest path edges = {{1, 6}, {1, 7}, {2, 6}, {2, 7}, {2, 8}, {3, 7}, {3, 9}, {4, 8}, {4, 9}, {4, 10}, {5, 9}, {5, 10}, {6, 1}, {7, 1}, {6, 2}, {7, 2}, {8, 2},...

you can definitely use Outer if you prefer a = Alphabet[]; b = Range[0,9]; list = Flatten[Outer[List, a,a,b,b,b,b], 5]; list//Length (* 6760000 *)

The problem has been finally resolved. I used some conditions to spit out the state of the system when any particle disappeared. I found that the main reason for particles to disappear was a pattern ...

mainlist={0.23, 0.34, 0.8, 0.0, -0.2, 0.4, -0.1}; positionlist={3,4,8,9,10,13,14}; ReplacePart[ConstantArray[0, 17], Thread[positionlist -> mainlist]] or what @Carl Woll suggested: finalresult = ...

list1 = {{1, 2, 0}, {1, 3, 0}, {4, 6, 0}, {2, 3, 0}, {3, 2, 0}}; list2 = {{3, 2, 1}, {1, 3, 1}, {4, 5, 1}}; replace[list1_, list2_] := Module[{temp, pos, val, l = list1}, temp = Outer[If[SameQ @@ ...

Module[{seg, img = img, cm, newComps, func}, seg = MorphologicalComponents[img]; cm = ComponentMeasurements[{seg, ColorNegate@img}, {"MaskedImage","BoundingBox"}]; newComps = ImageAdjust /@ ...

uses ReplaceRepeated in a recursive manner to generate the lists StringReplace[ Cases[List1, x_ /; StringStartsQ[x, ("Id" | "CreationDate" | "Tags")]], "&gt;" | "&lt;" -> ""] //. {p___, ...

BlockMap[{{#1[[1]], #[[1]]^2}, {#1[[2]], #[[2]]^2}} &, Range[3, 6], 2] (* {{{3, 9}, {4, 16}}, {{5, 25}, {6, 36}}} *)

ClearAll[testFunc]; Options[testFunc] = {opt -> 1}; testFunc[x_, OptionsPattern[]] := x^2 /; Range[4]~MemberQ~OptionValue[opt]; testFunc[x_, OptionsPattern[]] := "option provided out of range" ...

here is another way using Unitize π^2 Table[i (1 - Unitize[Range[1000] - i]), {i, 1000}]; // AbsoluteTiming (* {0.552622, Null} *) and with SparseArray alone: π^2 SparseArray[{i_, i_} :> i , {...

S = {s1, s2, s3, s4}; ls = SparseArray[{i_, j_} :> Correlation[S[[i]], S[[j]]] /; i > j, ConstantArray[Length@S,2]] // Quiet; ls//Normal (* {{0, 0, 0, 0}, {Correlation[s2, s1], 0, 0, 0}, {...

Map[First@Cases[#, {x_ /; x == Min[First @@@ #[[All, 1]]], pat : __ } :> pat , Infinity] &, list] or in a more succint and better way proposed by Kuba: Last@*First@*MinimalBy[First]/@ list ...

m = DeleteDuplicates[Map[Sort, Tuples[{a, b, c, d}, 3]]]; DeleteCases[m, {Alternatives@@Function[x, OrderlessPatternSequence[_, x, x], Listable], {b, c, d}]}] (*{{a, a, a}, {a, a, b}, {a, a, c}, {a, ...

basically if you deconstruct you will see that Element in your case operates on the sublist level {1, 2, 3} ∈ Integers (* True *) a ∈ Integers (* does not result in a boolean *) {4,5} ∈ Integers (* ...

here is a recursive way using tail-recursion and pattern matching Clear[func, partition,f]; func[x_List: {__}] := x /. {a___, patt : Repeated[PatternSequence[2, ___], {3}], c___} :> Join[{{a, ...

Tuples[Range[100], 2] or using Table as mentioned in the comment It is worth noting that the method relying on Tuples is 10-12 times faster than Table