Hot answers tagged

9

Using GaussianFilter on the raw RGB data will produce a convolution in all 3 dimensions of the list (rather than just the 2 spatial dimensions of the image). So filtering the raw data will also convolve RGB values at the same pixel. To see this effect, we can start with a uniform red image where all RGB values are {1,0,0}: test2 = Table[{1, 0, 0}, {m, 20}, ...


8

Probably the simplest way will be: reducedRows = ReplacePart[rows, Transpose[{toDrop}] -> Nothing[]]


8

Distribute[list, List] giving {{a, b, c, f, g}, {a, b, c, f, h}, {a, b, d, f, g}, {a, b, d, f, h}}


6

Make the to-be-dropped rows vanish: rows[[toDrop]] = ##&[] or as a function: f = Module[{m = #, d = #2}, m[[d]] = ##&[]; m] &; f[rows, toDrop] Some timings ClearAll[f0, f1, f2, f3, f4, f5] f0 = ReplacePart[#, Transpose[{#2}] -> Nothing[]]&; (* ciao's answer *) f1 = ReplacePart[#, Thread[#2 -> Sequence[]]] &; (* v9 version ...


6

No need to loop, and in general you'll want to use built-in, functional idioms for readability and performance, e.g.: Rest@Accumulate[a]/Range[2, Length@a] will give the desired result efficiently.


4

Thanks to J.M. I found a more elegant way to obtain the statinoary values that returned far simpler data, which was easy to plot. This is how my code looks now: ecf = s (p[t] - f[t]); ecp = -p[t] + d[t] f[t]; ecd = b (r - d[t] - f[t] p[t]); par = {s -> 3., b -> 1, r -> 100}; t0 = 800; tf = 850; estables[ra_] := Module[{par, solnum, points}, ...


4

There are a number of ways (if I understand aim),e.g.: lst = data = {{a1, b1}, {a2, b2}, {a3, b3}, {a4, b4}}; lst /. {x_, y_} :> {f[x], y} MapAt[f, lst, {All, 1}] {f@#1, #2} & @@@ lst


3

You want to Map here, not Apply: Map[Differences, list4] or just Differences/@list4 Map takes the sub-lists of list4 as the argument to Differences for each, Applyreplaces the heads (List) on the sub-lists with Differences (so the elements of the list all become arguments to Differences), hence the error message: Differences expects a list (and optional ...


3

Show[ListContourPlot[#, Contours -> {0}, ContourShading -> None, ContourStyle -> Directive[Thick, #2]] & @@@ {{list1, Red}, {list2, Green}}]


3

If I understand your question correctly, here is a possible approach to extracting the {x, y} list of values corresponding to the zeroes of your function when the function is only available through data points. First of all, I will generate a data list, since you did not provide one. Let's consider for instance the following function as an example: f[x_, ...


3

Here is a SparseArray solution (as prompted by BlacKow): vecs = Table[ SparseArray[ConstantArray[1/i, i], Length[a]], {i, 2, Length[a]}] a.# & /@ vecs


2

Make a function to select $n_x,n_y,n_z$ from the $i^{th}$ data set p[i_, n_] := d2[[i, All, n]] Another function to select all the time component t[i_] := d2[[i, All, 1]] Combine them properly for ListPlot data[i_, n_] := Partition[Riffle[t[i], p[i, n]], 2] For the $n_x$ component put $n=2$. Similarly you can plot it for $n=3,4$ ...


2

I might have misinterpreted the question. So, please do correct me if I am wrong and I will amend my answer. Based on my understanding, please see implementation below. Example: (*Extract all sub-lists who's length is exactly 4*) data = (Select[raw, Length @ # == 4 &]); (*Here I plot x, y and z sets vs time*) ListPlot[data[[All, {1, #}]] & /@ ...


2

Not as elegant as Distribute, but there is also Tuples: Tuples[List /@ list /. {{x__}} :> {x}] {{a, b, c, f, g}, {a, b, c, f, h}, {a, b, d, f, g}, {a, b, d, f, h}} and Outer: Flatten[Outer[List, ## & @@ (List /@ list /. {{x__}} :> {x})], 4] {{a, b, c, f, g}, {a, b, c, f, h}, {a, b, d, f, g}, {a, b, d, f, h}}


2

The WriteString in your loop form should be: WriteString[path, 0.01*i, " ", 1/((y[30]^2 + y[30 - Pi/2]^2)) /. First@s, "\n"] This gives you no { } in the file and Imports properly. You could also use Write: Write[path, 0.01*i, OutputForm[" "], 1/((y[30]^2 + y[30 - Pi/2]^2)) /. First@s] That said its usually preferable to generate ...


2

You can first find all the roots by their z value, and then select out the first point that touches zero. For example: ε0 = 1.*^-3; ListPlot[Table[ First /@ SplitBy[ Sort[Select[ls, Abs[#[[3]]] < ε0 &][[All, 1 ;; 2]]], First], {ls, {list1, list2}}], PlotRange -> All]


2

Not sure about a built-in, but you can do MapThread[Association, Normal@*Normal /@ {ds1, ds2}] {<|"a" -> 1, 10 -> 3|>, <|"b" -> 2, 20 -> 4|>}


1

If you want to simplify generating the input these are simpler ways: x = Range[4]; y = Partition[ Range[7], 4, 1]; then you can use Inner: z = Inner[List, x, y, List]; and finally ListPlot[z] Instead of playing with Partition and Range you can generate the input of ListPlot with Table: z = Table[{i, i + k - 1}, {k, 4}, {i, 4}]; or even better ...


1

You are trying to export an Array as a Table, and the system is taking each element at the second level and printing it as you would a number, but in this case it is another list. You just need to flatten each 2 by 2 line in order to export as a "Table" Export["list.dat", Flatten /@ list, "Table"]//Import//Dimensions (* {2726, 4} *)


1

Defining Clear@list list[a_, b_, c_] := Union[Range[a, Prime[b], Prime[c]], Range[a + 2, Prime[b], Prime[c]]] we can get your list of Unions using the function Clear@list2 list2[n_, range_List] := Union @@ MapThread[list[#1, n, #2] &, {#, range}] & /@ Tuples[Range[0, # - 1] & /@ range]; where n is the 8 and range is the possible values for ...


1

A solution that keeps instead of drops. toKeep = Select[Range[r], PrimeQ /* Not]; reducedRows = rows[[toKeep]]; Hope this helps.


1

We should not try to hide that it can be done by indexing over a, and since the OP specifically asked for such a solution, I think he deserves to get one. This is what occurred to me. progressiveMean[a_List] := Module[{prev = a[[1]], next}, Rest @ Table[ next = (a[[i]] + (i - 1) prev)/i; prev = next, {i, 2, Length[a]}]] a = {5, ...



Only top voted, non community-wiki answers of a minimum length are eligible