Regarding the shape of a scalar value
5 posts
• Page 1 of 1
Regarding the shape of a scalar value
Hi,
In the following code:
=> results nothing (Empty line)
but
=> 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?
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?
-
firesofmay - Posts: 7
- Joined: Sat Jun 27, 2015 2:50 pm
Re: Regarding the shape of a scalar value
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:
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.
- 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
Hmm. Interesting.
but then what is being returned? Is it a null value?
but then what is being returned? Is it a null value?
-
firesofmay - Posts: 7
- Joined: Sat Jun 27, 2015 2:50 pm
Re: Regarding the shape of a scalar value
What is being returned (and displayed) is an empty vector. For example:
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.
- 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
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.
-
firesofmay - Posts: 7
- Joined: Sat Jun 27, 2015 2:50 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group