Regarding the shape of a scalar value

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

Regarding the shape of a scalar value

Postby firesofmay on Mon Jun 29, 2015 3:19 pm

Hi,

In the following code:
      ⍴ 10

=> results nothing (Empty line)

but
      ⍴ 20 10

=> 2

Q. Why does shape of a number or scalar values return nothing?
Q. Why did it not return 1 instead?
Q. Is that really nothing? Or its just not being printed? Is it like some kind of null value?

Thanks! :)

PS: On a side note, is above the right way to show what my code was and what the output is?
User avatar
firesofmay
 
Posts: 7
Joined: Sat Jun 27, 2015 2:50 pm

Re: Regarding the shape of a scalar value

Postby Roger|Dyalog on Mon Jun 29, 2015 5:18 pm

The shape of an array is a vector. The shape of a matrix has 2 elements; the shape of a vector has 1 element; the shape of a scalar has ... 0 elements! The shape of a scalar is a vector and it has 0 elements, so the shape of a scalar is the empty vector. Therefore:
Code: Select all
      ⍴ 10

(empty line of output.)

Answers to your questions:

Q. Why does shape of a number or scalar values return nothing?

It returns something, but the display of that thing is an empty line.

Q. Why did it not return 1 instead?

Because, a display of 1, coupled with the fact that the result of ⍴ is always a vector, would mean that a scalar has shape ,1. The shape of a scalar is not 1.

Q. Is that really nothing? Or its just not being printed? Is it like some kind of null value?

It's not nothing.
Roger|Dyalog
 
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Re: Regarding the shape of a scalar value

Postby firesofmay on Mon Jun 29, 2015 8:28 pm

Hmm. Interesting.
but then what is being returned? Is it a null value?
User avatar
firesofmay
 
Posts: 7
Joined: Sat Jun 27, 2015 2:50 pm

Re: Regarding the shape of a scalar value

Postby Roger|Dyalog on Mon Jun 29, 2015 10:09 pm

What is being returned (and displayed) is an empty vector. For example:

Code: Select all
      t←⍴10
      t   ⍝ blank line of output

      ⍴t
0
      ⍴⍴t
1

The rank of t (⍴⍴t) is 1, so t is a vector. Its shape (⍴t) is 0, so t is an empty vector. An empty vector is not nothing.

Old joke: Define "nothing", and give an example; define "the universe", and give two examples.
Roger|Dyalog
 
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Re: Regarding the shape of a scalar value

Postby firesofmay on Tue Jun 30, 2015 7:40 pm

Ah! Now I get it. This makes sense. Maybe this being part of the book might actually be helpful in understanding that its not "nothing" :)

Roger|Dyalog wrote:What is being returned (and displayed) is an empty vector. For example:

Code: Select all
      t←⍴10
      t   ⍝ blank line of output

      ⍴t
0
      ⍴⍴t
1

The rank of t (⍴⍴t) is 1, so t is a vector. Its shape (⍴t) is 0, so t is an empty vector. An empty vector is not nothing.

Old joke: Define "nothing", and give an example; define "the universe", and give two examples.
User avatar
firesofmay
 
Posts: 7
Joined: Sat Jun 27, 2015 2:50 pm


Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest