Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
A function like Select that returns positions instead of values
ResourceFunction["SelectPositions"][list,crit] picks out all positions pi of list for which crit[elementi] is True. | |
ResourceFunction["SelectPositions"][list,crit,n] picks out the first n positions for which crit[elementi] is True. | |
ResourceFunction["SelectPositions"][crit] represents an operator form of ResourceFunction["SelectPositions"] that can be applied to an expression. |
Select positions that have even elements:
In[1]:= | ![]() |
Out[1]= | ![]() |
Use a pure function to test each element:
In[2]:= | ![]() |
Out[2]= | ![]() |
Return only the first position selected:
In[3]:= | ![]() |
Out[3]= | ![]() |
Use the operator form of SelectPositions:
In[4]:= | ![]() |
Out[4]= | ![]() |
SelectPositions operates on values in an Association:
In[5]:= | ![]() |
Out[5]= | ![]() |
SelectPositions picks out positions for which applying the criterion explicitly yields True:
In[6]:= | ![]() |
Out[6]= | ![]() |
Applying the criterion to the symbolic object x does not explicitly yield True:
In[7]:= | ![]() |
Out[7]= | ![]() |
Find positions of pairs containing x:
In[8]:= | ![]() |
Out[8]= | ![]() |
Find up to two pairs containing x:
In[9]:= | ![]() |
Out[9]= | ![]() |
Fewer than the requested elements may be returned:
In[10]:= | ![]() |
Out[10]= | ![]() |
Use an operator form as selection criterion:
In[11]:= | ![]() |
Out[11]= | ![]() |
Use SelectPositions in operator form:
In[12]:= | ![]() |
Out[12]= | ![]() |
SelectPositions works with any head, not just List:
In[13]:= | ![]() |
Out[13]= | ![]() |
SelectPositions works with SparseArray objects:
In[14]:= | ![]() |
Out[14]= | ![]() |
In[15]:= | ![]() |
Out[15]= | ![]() |
In[16]:= | ![]() |
Out[16]= | ![]() |
Get positions of elements that match a criterion for use in other functions:
In[17]:= | ![]() |
Out[17]= | ![]() |
In[18]:= | ![]() |
Out[18]= | ![]() |
Use with Extract:
In[19]:= | ![]() |
Out[19]= | ![]() |
Use with ReplacePart:
In[20]:= | ![]() |
Out[20]= | ![]() |
Use with MapAt:
In[21]:= | ![]() |
Out[21]= | ![]() |
Use with Insert:
In[22]:= | ![]() |
Out[22]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License