# Passing empty matrix as data in JSON file

**URL:** https://discourse.mc-stan.org/t/passing-empty-matrix-as-data-in-json-file/8261
**Category:** CmdStan
**Created:** [March 27, 2019, 6:36pm UTC](https://discourse.mc-stan.org/t/passing-empty-matrix-as-data-in-json-file/8261 "2019-03-27T18:36:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![lciti](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/lciti/32/4430_2.png) [@lciti](https://discourse.mc-stan.org/u/lciti)
#### Post date: [March 27, 2019, 6:36pm UTC](https://discourse.mc-stan.org/t/passing-empty-matrix-as-data-in-json-file/8261/1 "2019-03-27T18:36:52Z")

</div>

How can I create an empty matrix when passing a JSON data file to cmd-stan?

I have the following in my stan file

```
data {
    int n_inputs;
    int n_samples;
    matrix[n_inputs,n_samples] U;
    ...
}

```

My JSON file contains:

```
{ "U": [], "n_inputs": 0, "n_samples": 100, ... }

```

but I get the error `variable: U, error: empty array not allowed`.

I am using Stan-2.19.

---

<div class="post-metadata">

### Author: ![Max\_Mantei](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/max_mantei/32/7912_2.png) [@Max\_Mantei](https://discourse.mc-stan.org/u/Max_Mantei)
#### Post date: [March 27, 2019, 6:51pm UTC](https://discourse.mc-stan.org/t/passing-empty-matrix-as-data-in-json-file/8261/2 "2019-03-27T18:51:07Z")

</div>

Why would you want to do that?

Couldn’t you use the `generated data` or `generated quantities` block for what you are trying to do?

---

<div class="post-metadata">

### Author: ![lciti](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/lciti/32/4430_2.png) [@lciti](https://discourse.mc-stan.org/u/lciti)
#### Post date: [March 27, 2019, 11:31pm UTC](https://discourse.mc-stan.org/t/passing-empty-matrix-as-data-in-json-file/8261/3 "2019-03-27T23:31:33Z")

</div>

Hi Max\_Mantei

Thanks for taking the time to reply to my question.  
I would like my code to work with any size of U, including when U is empty.  
This is working fine for me in pystan (and I think it is also allowed in R-stan, see [this thread](https://discourse.mc-stan.org/t/passing-empty-list-array-of-matrices-as-data/883)). I am now trying the same code in cmd-stan 2.19 because I want to try the new offset-multiplier feature, which isn’t yet available in pystan (still at 2.18).  
I was wondering how one could pass an empty array. I agree one could use a number of tricks (e.g. having `U` with `rows_U` (\>0) rows but only reading its first `n_inputs` rows) but I am sure there must be a cleaner way.

Best,  
Luca
