Questions tagged [j]
J is a high-level, general-purpose, high-performance array programming language.
427
questions
1
vote
2
answers
73
views
Print char of string uppercase if it is a vowel and lowercase if it is a consonant
I am trying to come up with a verb that will take a string as input
and printa character uppercase if it is a vowel i.e. (aeiou) or lowercase
if it is a consonant.
s=:'authority'
t=:<&>s
│a│...
3
votes
1
answer
66
views
Jconsole is complaining "file name error"
I am having trouble compiling and running J Programming Language
The Jconsole binary file (From J Language) throws an error when executed:
|file name error
| 0!:0 y
it compiled almost ...
0
votes
1
answer
57
views
How can I fix 'noun result was required' error in J?
I'm trying to do the 4th Advent of Code problem using J, and I've ran into lots of problems, but now I have a code that looks like this:
fn =. < 'D:/PyCharm/AOC/output4.txt'
data =. freads fn
...
2
votes
0
answers
78
views
Trying to understand why my custom function seems to be ignoring most of it's arguments
Defining a simple fibonacci function as:
fib=: verb : '{. (({: , +/ )^:y) 0 1'
I expected to be able to call it as
fib 5 6 7 NB. expected 5 8 13
but instead I get
fib 5 6 7
5 8
Trying to ...
2
votes
1
answer
140
views
Convert boxed array to normal array?
Suppose I have a boxed array like;
┌─┬─┬─┐
│1│2│3│
└─┴─┴─┘
how do I covert it to a normal array such as 1 2 3?
2
votes
1
answer
67
views
Convert array of strings to array of integers
How do I convert types in J?
For example, how to I convert an array of strings like "4" "78" "0" "_1" to an array of numbers like 4 78 0 _1
2
votes
1
answer
39
views
Replace atom in array of strings
Suppose I have an array of strings "31,793.1" "29,798.6" "30,455.7" "29,700.9"
How do I replace , with nothing to give me "31793.1" "29798.6"...
3
votes
2
answers
108
views
Read column of CSV file as array
I am trying to read a column from a CSV file into an array.
So far I have successfully read the file with the code below.
load 'csv'
data =: readcsv '/Users/max/Desktop/prices.csv'
Typing data in ...
6
votes
2
answers
161
views
What is the "j" expression for the "maximum consecutive ones" problem?
In the paper "Combinatory Logic and Combinators in Array Languages" they give a solution in APL:
vec ← 1 1 0 1 1 1 0 0 0 1
⍝ split (partition) on zeroes
⊆⍨vec
┌───┬─────┬─┐
...
4
votes
0
answers
62
views
How to expand memoization table in J
Previous discussion is on Memoization in J which doesn't answer the issue. The problem is that using memoization M. somehow makes the program much slower.
I encountered the same problem. Consider this ...
2
votes
1
answer
85
views
What does the dyad `=` do to boxed strings?
If x were a boxed string, I expect x=<'ABC' to compare the >x to 'ABC' to see if they are equal, but the following example shows that this is not the case. The J vocabulary document doesn't say ...
1
vote
2
answers
128
views
Building an array of verbs in J
Is it possible to build arrays of verbs?
I've tried this:
f =: >:
f2 =: f f
There's no syntax error but f2 is clearly not an array of verbs.
For instance
f2 yields f f
$ f2 yields $ f2
0 { f2 ...
2
votes
1
answer
99
views
In j, how can I define a verb locally in one scope and pass it to a defined adverb?
I am getting an unexpected value error when I use a name to pass a verb as the argument to an adverb.
The adverb (integer binary search with predicate u and bounds x):
bsearch=: adverb define
r=. y ...
2
votes
1
answer
123
views
Amend with bond to new data shows unexpected behaviour
I have been using J for a couple of weeks now and recently started using it for simple problems rather than just toying with concepts.
This problem needs to replace all x characters in a string into y,...
1
vote
1
answer
112
views
How to turn a table or matrix into a (flat) list in J
I know how to reshape a list into a table. But how do I turn a table into a list or uni- dimensional array.
my_list=:3 4 $i.12
0 1 2 3
4 5 6 7
8 9 10 11
And is it better to perform operations on ...
2
votes
1
answer
79
views
How to run dissect in J?
I have J9.02 installed in Debian-based OS. I try to run dissect but it fails:
load 'debug/dissect'
dissect '10 + i. 3 3'
value error
|value error: wd
| wd DISSECT
|value error: wd
| ...
3
votes
2
answers
107
views
How to define selection using index function in J
Let's assume I have a following tensor t:
]m=: 100 + 4 4 $ i.16
100 101 102 103
104 105 106 107
108 109 110 111
112 113 114 115
]t=: (m ,: m+100) , m+200
100 101 102 103
104 105 106 107
108 109 ...
1
vote
1
answer
122
views
How to exit the J console?
I recently downloaded j902 and can launch the console from my terminal, but I don't know how to exit. I tried “Ctrl + C” and "exit" but they did not work.
How do I exit the J console?
3
votes
1
answer
131
views
Find 4-neighbors using J
I'm trying to find the 4-neighbors of all 1's in a matrix of 0's and 1's using the J programming language. I have a method worked out, but am trying to find a method that is more compact.
To ...
3
votes
2
answers
132
views
Writing custom verbs in J
When you write your custom verbs(functions) should you use the following convention:
convert degrees fahrenheit to celsius.
centigrade =: 3 : 0
t1 =. y - 32
t2 =. t1 * 5
t3 =. t2 % 9
)
...
1
vote
0
answers
88
views
where does j save the result of its last operation?
In python's repl, _ holds the value of the last operation.
Where is the value of the last operation saved in the j repl?
2
votes
0
answers
85
views
what does 1: mean in the verb train (100 $ - {. 1:)"0
the j solution to the 100 doors problem in rosetta code is ~:/ (100 $ - {. 1:)"0 >:i.100
>: i. 100 means 'make a list of numbers from 1 to 100'
(100 $ - {. 1:)"0 >: i. 100 means '...
2
votes
1
answer
94
views
How to use arbitrary selector in interchange in J lang?
Let's assume we have a vector and matrix like below:
r =: 100 + 5 5 $ i.25
r
100 101 102 103 104
105 106 107 108 109
110 111 112 113 114
115 116 117 118 119
120 121 122 123 124
v =: 100 + 5 $...
2
votes
3
answers
149
views
How do I negate a selector in J lang?
I am playing with selection. Let's look at the initial example:
rarg=. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
_1 (<(<0 1),(<0 1)) } ( 4 4 $ rarg)
_1 _1 2 3
_1 _1 6 7
8 9 10 11
12 13 ...
3
votes
2
answers
111
views
different result once square root is added inside tacit
Very new to J. I love it but still far from fluent in it.
I have managed to hit an issue and I don't know why it is happening. If somebody could please explain why this is occuring I could learn more ...
2
votes
2
answers
164
views
Sum of arrays with repeated indices
How can I add an array of numbers to another array by indices? Especially with repeated indices. Like that
x
1 2 3 4
idx
0 1 0
y
5 6 7
] x add idx;y NB. (1 + 5 + 7) , (2 + 6) , 3 , 4
13 8 3 ...
3
votes
1
answer
127
views
Need help parsing the meaning of "i.~"
I'm trying to understand the solution for day 1 part 2: https://code.jsoftware.com/wiki/Essays/Advent_Of_Code#Part_2
PART2=: >: _1 i.~ +/\ 1 _1 mp '()'=/read'input'
I feel like I understand most ...
2
votes
1
answer
122
views
How to drop columns of csv data in J
I have a lot of csv files that I have to drop the date column.
I have a J line that reads in csv file into a numeric array, rdtabfile =: (0&".;.2@:(TAB&,)@:}:);._2) @ ReadFile @<
2
votes
1
answer
74
views
amend a subarray in place in j?
I've got two ways to amend a subarray in J but I don't like either of them.
(Imagine selecting a rectangle in a paint program and applying some arbitrary
operation to that rectangle in place.)
t =. ...
1
vote
1
answer
102
views
Using less trivial random generation in J lang
I am experimenting with random generation using J and would have a couple of questions that occured:
If I want to pick random 10-character word I can use
(?10 # 26) { 'abcdefghijklmnopqrstuvwxyz'
...
3
votes
4
answers
107
views
Get whole result when using J console
When using J console ijconsole I get only results up to some. For example,
ijconsole -js "a=. 3 3 5 6 " "echo 200 $ a" "exit''"
3 3 5 6 3 3 5 6 3 3 5 6 3 3 5 6 3 3 5 6 ...
2
votes
0
answers
79
views
J packages with sparse matrix algorithms
Are there any J packages with sparse matrix algorithms that enhance the functionalities mentioned here:
https://www.jsoftware.com/help/dictionary/d211.htm ?
For example, Singular Value Decomposition (...
4
votes
3
answers
272
views
Write 4 : 'x&{.&.;: y' tacitly
Conor Hoekstra recently solved a Leetcode problem in APL https://youtu.be/QtvvQ7MdwKY The problem is to take the first x words from a character string y
In J, using &. (Under) and ;: (Words) I can ...
4
votes
2
answers
156
views
Sorting words in a string by their length in J
I have the following string:
s=:'when can we dance'
I can find the length of each word with this:
# each ;:s
I can sort the lengths in ascending/descending order:(/:~) # each ;:s which gives me boxed ...
3
votes
1
answer
80
views
Amend with multiple indices per substitution in J
In J, how do you idiomatically amend an array when you have:
substitution0 multipleIndices0
...
substitutionN multipleIndicesN
(not to be confused with:
substitution0 multipartIndex0
...
...
2
votes
2
answers
136
views
How can I take the outer product of string vectors in J?
I'm trying to replicate the outer product notation in APL:
∘.,⍨ 'x1' 'y1' 'z1' 'x2' 'y2' 'z2' 'x3' 'y3' 'z3'
which yields
x1x1 x1y1 x1z1 x1x2 x1y2 x1z2 x1x3 x1y3 x1z3
y1x1 y1y1 y1z1 y1x2 y1y2 y1z2 ...
4
votes
2
answers
125
views
Is there an idiomatic way to print a vector(list) or a character string diagonally in J?
if I have a list a=:i.5, can it be printed like this(diagonally):
0
1
2
3
4
or in the case of a string like 'enigmatic' can a 'x' pattern be generated?
e e
n n
i i
g g
...
3
votes
2
answers
145
views
Index of minimum element using J
In J it is trivial to find the minimum element of an array:
<./ 5 6 4 9
4
But how to find the index of the minimum element using J?
(In case this is an XY problem, I should say that I want the ...
1
vote
3
answers
129
views
J programming how to wait fo X seconds before executing the next verb?
I want to wait for X seconds before executing the next line in a verb.
So far, I have tried this foreign command 6!:3 (2.5) found in time (delay) though it looks like the entire verb execution is ...
2
votes
1
answer
189
views
How to reshape data array from wide to long in J?
I like to replicate the reshape function in J.
For example, Stata can reshape a dataset "from wide to long". Below is their Example 1 from their documentation:
. use http://www.stata-press....
3
votes
4
answers
162
views
Run J script as if it were line-by-line entered into the interpreter
Is there a way to run the script as if it were typed into the interpeter? The benefits are that I don't need echos everywhere, the work done is saved as a file, and I can use vim to do the editing. ...
2
votes
1
answer
84
views
Print values and it's associated index when working with vectors / matrix in J
If I want to check how many values in a vector or matrix are less than a given value
I can use +/ (a < 20). But what if I wanted to know both the specific value and it's index.
Something like (2(...
1
vote
1
answer
65
views
where is the official documentation for .Alpha_j_
David Lambert's code here gets the letters (Alphabet), using the following:
26}.Alpha_j_ NB. output is abcdefghijklmnopqrstuvwxyz
Where can I find the offical documentation for ".Alpha_j_"...
3
votes
0
answers
104
views
Is it possible to store boxed arrays as memory mapped files in J?
I have data that works well in j files and key files but for possible performance reasons memory mapped files make more sense. At one time J did have MMF's for boxed arrays but I think it was ...
0
votes
1
answer
74
views
How to apply same fetch x value to different cells in structured array
For a 3 row array of a boxed structure e.g. q
]q=: ,. (0;'At least one uppercase letter';'At least one special character from "#$%^"';'Must be 10 to 30 characters long') ; (1;'...
1
vote
2
answers
311
views
How to configure org mode to evaluate J code blocks?
When I run a J code block in org mode the java jconsole pops up instead. So must be sending a jconsole command instead of ijconsole... Of course J code block is not evaluated.
How do I fix this so ...
1
vote
1
answer
66
views
atomic representation of a sentence for noun initialization
In a data structure such as
I want to be able to use ". (do) to initialize what could be a long list of noun names on the left with the values on the right in a nested array. A value could be a ...
3
votes
1
answer
209
views
What is the most efficient way to insert a number into an ordered array?
Inserting numbers into a sorted array is a very common need.
Mathematica stack exchange for reference. Its priority queue appears extremely fast.
https://mathematica.stackexchange.com/questions/224249/...
1
vote
1
answer
320
views
Seeking example that use the J programming language JHS web server as a service
The J programming language includes an embedded web server called JHS. The binary download comes with (on the mac) an app called jhs.app, which is, I think, intended to run JHS. However, there is no ...
2
votes
1
answer
120
views
How can I manipulate/extract info from the following table in J
]data=:_3 ]\ 'Jack';23;178;'Rick';27;181;'Alice';41;178;'Mitch';31;184;'Paul';32;179
┌─────┬──┬───┐
│Jack │23│178│
├─────┼──┼───┤
│Rick │27│181│
├─────┼──┼───┤
│Alice│41│178│
├─────┼──┼───┤
│Mitch│31│...