# Size( ,k) of one-dimensional array for k \>1

**URL:** <https://discourse.julialang.org/t/size-k-of-one-dimensional-array-for-k-1/4378>\
**Category:** General Usage\
**Created:** [June 20, 2017, 6:51pm UTC](https://discourse.julialang.org/t/size-k-of-one-dimensional-array-for-k-1/4378 "2017-06-20T18:51:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![austinbean](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@austinbean](https://discourse.julialang.org/u/austinbean)\
**Post date:** [June 20, 2017, 6:51pm UTC](https://discourse.julialang.org/t/size-k-of-one-dimensional-array-for-k-1/4378/1 "2017-06-20T18:51:14Z")

</div>

```julia
v1 = rand(5);

size(v1) # returns (5,)

size(v1, 1) = 5 # fine
size(v1, 2) = 1 # ?
size(v1, 3) = 1 # ??
...
size(v1,100) = 1 # ? ... ?

```

I think I would have expected size(v1, k) for k \> 1 to be 0, not 1. Is this intended behavior? Perhaps it has the potential to mislead. Is there some other design consideration I’m ignoring? The problem arose for me because I did the following:

```julia
l, w = size(v1) # I expected (1,0)
ERROR: BoundsError: attempt to access (5,)
  at index [2]

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [June 20, 2017, 7:00pm UTC](https://discourse.julialang.org/t/size-k-of-one-dimensional-array-for-k-1/4378/2 "2017-06-20T19:00:40Z")

</div>

I’d justify this by saying that the number of elements in an array `A` should always be `prod(size(A))` – as soon as `size(A, i)` returns `0` for some `i` you’d get an empty array.

Your original problem should be written as

```julia
l, w = size(v1, 1, 2)

```

which is explicit about the dimensions you care about.

---

<div class="post-metadata">

**Author:** ![austinbean](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@austinbean](https://discourse.julialang.org/u/austinbean)\
**Post date:** [June 20, 2017, 7:10pm UTC](https://discourse.julialang.org/t/size-k-of-one-dimensional-array-for-k-1/4378/3 "2017-06-20T19:10:29Z")

</div>

That is indeed a good reason. Thanks. It’s a little weird to get non-zero sizes for other dimensions in an empty array! But I see your larger point.

```julia
size([])
   (0,)

size([], 1, 2,3) 
   (0,1,1)

```

Your suggestion is what I ended up doing.

Thanks for your reply!
