- Aggregated Pivot Table
- Bit Shifting
- Bitwise XOR
- Calculate Tick Size
- Collapsing Dictionaries
- Graphs - Breadth First Search
- Graphs - Depth First Search
- Graphs - Detecting Cycles
- Greatest Common Divisor
- Identity Matrix
- Least Common Multiple
- Log Parser
- Nanosleep
- One Hot Encoding
- Parent Child ID Mapping
- Slippage
- Split Training and Testing Sets
- Stratified Sampling
- Symbol Column Update
- Table Indexing
- Word Count
Identity Matrix
Question: Define a function 'im' that returns an n x n identity matrix
More Information:
https://en.wikipedia.org/wiki/Identity_matrixExample
q)im[3]
100b
010b
001b
Solution
######## solution.q ########
im:{n=\:n:til x}
Explanation: Use 'til' to create n elements in incremental order. The next expression 'n=\:n' does an equality comparison between every atom of the left handside list with the whole list on the right handside. This returns an n x n matrix, and each equality is true for every position (i,i), where i is a list index. Note: each-right can be used instead of each-left.