Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

New answers tagged

1

Each of the elements in the list only has a single set catogerisation ('Head'). As kglr says, using Head /@ {1, 3.1, 2/3, x, 3 + I, "Yellow"} Will show what each of these elements are catogerised as. In this case it is {Integer, Real, Rational, Symbol, Complex, String}, respectively. Head: Integer is only used for... well... integers. Real is being ...


7

Alternative solution with FilteredEntityClass and EntityFunction The code For the sake of documenting this one more time on this site, a more general answer (w.r.t. the answer of Carl) would be to use EntityFunction and FilteredEntityClass. In this particular case, one additional subtlety is that in this method, one has to compare the "Continent" property ...


7

You can use the operator UnequalTo for this purpose: EntityList @ EntityClass["Country", "Continent"->UnequalTo["Europe"]] {Entity["Country", "Afghanistan"], Entity["Country", "Algeria"], Entity["Country", "AmericanSamoa"], Entity["Country", "Angola"], Entity["Country", "Anguilla"], Entity["Country", "Antarctica"], Entity["Country", "...


3

An alternative way to use Pick: With[{d = data[[All, 2]]}, Pick[data, UnitStep[d - 1] (1 - UnitStep[d - 2]), 1]] % == Select[data, 1.0 < #[[2]] < 2.0 &] True You can also useBinLists: BinLists[data, {{-∞, ∞}}, {{1 + $MachineEpsilon, 2 - $MachineEpsilon}}][[1, 1]] % == Select[data, 1.0 < #[[2]] < 2.0 &] True Although not as ...


3

Pick[data, Unitize[Clip[data[[All, 2]], {1, 2}, {0, 0}]], 1] This should be faster than methods posted or in comments so far.


4

Select[data, Last /* Between[{1, 2}]] will do the trick and has the benefit of being readable.


5

data = {{0., 2.}, {0.05, 2.01597}, {0.1, 2.03223}, {0.15, 2.04913}, {0.2, 2.06704}, {0.25, 2.08641}, {0.3, 2.10784}, {0.35, 2.13212}, {0.4, 2.16039}, {0.45, 2.19429}, {0.5, 2.23637}, {0.55, 2.29066}, {0.6, 2.36381}, {0.65, 2.46671}, {0.7, 2.61553}, {0.75, 4.82404}, {0.8, 1.07405}, {0.85, 1.30513}, {0.9, 1.47802}, {0.95, 1.59783}, {1., 1.68171}, {1.05, 1....


5

You can use Complement: Complement[A, B] {1, 3, 5} Also A /. Alternatives @@ B -> Nothing {1, 3, 5} and DeleteCases[A, Alternatives @@ B] {1, 3, 5} Cases[Except[Alternatives @@ B]] @ A {1, 3, 5}


2

Expanding on @Lukas Lang's comment, the problem comes from the default level specification of Cases and the fact that f appears as the head (or rather, at part 0/only in level 0) in f[a,b,c]. From the Cases documentation The default value for levelspec in Cases is {1}. So when a level is specified, say for example as Cases[f[a, b, c], _f, Infinity], ...


1

Let's use this method. Play with parameters if it is necessary. xScale = 2.; xy = Transpose[{N[Range[Length[data]]]*(xScale/Length[data]), data}]; start = {-xScale, Mean[data]}; finish = {2*xScale, Mean[data]}; graph = NearestNeighborGraph[Join[{start}, xy, {finish}], 10]; graph = SetProperty[graph, EdgeWeight -> ...


1

The following can be used if the csv files are imported as strings. Select automatically iterates over a List of data. So given a data like this data = RandomWord["CommonWords", 10] The following will select the data of more than a certain length: Select[data, StringLength[#] > 7 &] If the data is already parsed like data=Table[Table[RandomWord[...


2

$indicesToExclude = {10, 35}; arr := Array[MyNonLinearEquation, MyLength]; (* First method - just don't use them! Note you have contiguous sequence. *) tL1 = First@RepeatedTiming[(l1 = MyNonLinearEquation /@ DeleteCases[Range[MyLength], Alternatives @@ $indicesToExclude]);]; (* Second method - just don't use them! Say you don't contiguous ...


5

You can use the fourth argument of Array to delete unwanted positions: Array[foo, 10, 1, Delete[{##}, {{3}, {7}}] &] {foo[1], foo[2], foo[4], foo[5], foo[6], foo[8], foo[9], foo[10]} Define bar to be equal to Nothing for the arguments you want to skip and to foo for all other arguments: bar = foo; bar[3 | 7] = Nothing; Array[bar, 10] {foo[...


Top 50 recent answers are included