You probably do not need a readtensor verb for your application.

Those capabilities are waiting there in J for you to use them*,
however most (maybe all?) applications tend to need only a small
fraction of the general capabilities implemented in J.

* As an example use of higher dimensioned arrays, consider the cube
verb in the fast fourier transform implementation at
http://code.jsoftware.com/wiki/Essays/FFT

Thanks,

-- 
Raul


On Thu, Apr 20, 2017 at 9:23 AM, Michael Goodrich
<[email protected]> wrote:
> Raul,
>
> I see your point.  I was expecting too much from 'readtable', and I
> apparently need a 'readtensor' verb for my app.
>
> On Sun, Apr 16, 2017 at 4:02 PM, Raul Miller <[email protected]> wrote:
>
>> On Sun, Apr 16, 2017 at 2:26 PM, Michael Goodrich
>> <[email protected]> wrote:
>> > Why does J not treat a column of numbers as a N by 1 'matrix' ie a vector
>> > rather than a list?
>>
>> From my point of view, J does treat a column of numbers as an N by 1
>> matrix.
>>
>> But perhaps it is better to go over specific examples (like other
>> people have been doing here).
>>
>>    $,.1 2 3 2 1
>> 5 1
>>    ($,.1 2 3 2 1)
>> 5 1
>>    $,:1 2 3 2 1
>> 1 5
>>    $(,.1 2 3 2 1) +/ .* ,:1 2 3 2 1
>> 5 5
>>    $(,:1 2 3 2 1) +/ .* ,.1 2 3 2 1
>> 1 1
>>
>> But the real issue here is readtable defined at
>> http://www.jsoftware.com/help/primer/files.htm
>>
>> readtable =: 3 : 0
>> d =. 1!:1 y
>> d =. toJ d
>> d =. cutopen d
>> d =. 0 ". each d
>> d =. > d
>> )
>>
>> Here, as Chris Burke pointed out, each line of the file is converted
>> to numeric form using 0 ". expression, and when a line contains only
>> one number you do not get a list of numbers of shape 1, but instead
>> just get a number. When these results are merged into the final form
>> you get a list instead of a table. (But this list is a vector, from a
>> J point of view... if that seems confusing, bear with me.)
>>
>> The underlying issue that I think you might be asking about is that
>> the mathematical point of view which J was built on was tensor algebra
>> rather than matrix algebra. So, rather than "everything is a matrix"
>> we instead go with "everything is a tensor" (or, in the jargon used by
>> many computer programmers: "everything is an array of arbitrary
>> dimension").
>>
>> So, going back a bit, when we do something like 0 ". '93' we get a
>> result which is an numeric array with zero dimensions.
>>
>> If you wanted to force readtable to always return a matrix result, you
>> could do something like this:
>>
>> readtable =: 3 : 0
>>   d =. 1!:1 y
>>   d =. toJ d
>>   d =. cutopen d
>>   d =. 0 ". each d
>>   d =. , each d
>>   d =. > d
>> )
>>
>> This will force each individual line to be a 1 dimensional array, so
>> when they are assembled into the result you always will get a matrix.
>> (And note that you do not have to worry about the analogous issue for
>> one row files because cutopen always returns a list of boxes.)
>>
>> I hope this helps,
>>
>> --
>> Raul
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
>
>
> --
> Dominus enim Iesus Ecclesiae Suae et,
>
> -Michael
>
>
> "Let your religion be less of a theory and more of a love affair."
>                                              - G.K. Chesterton
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to