# Stack numpy array as output of complex function produces ValueError: order must be one of 'C', 'F', 'A', or 'K' (got 's0f')

**URL:** <https://discourse.pymc.io/t/stack-numpy-array-as-output-of-complex-function-produces-valueerror-order-must-be-one-of-c-f-a-or-k-got-s0f/7421>\
**Category:** Questions\
**Tags:** theano\
**Created:** [May 11, 2021, 10:02pm UTC](https://discourse.pymc.io/t/stack-numpy-array-as-output-of-complex-function-produces-valueerror-order-must-be-one-of-c-f-a-or-k-got-s0f/7421 "2021-05-11T22:02:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![verderis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/verderis/32/485_2.png) [@verderis](https://discourse.pymc.io/u/verderis)\
**Post date:** [May 11, 2021, 10:02pm UTC](https://discourse.pymc.io/t/stack-numpy-array-as-output-of-complex-function-produces-valueerror-order-must-be-one-of-c-f-a-or-k-got-s0f/7421/1 "2021-05-11T22:02:59Z")

</div>

I have a large function of several random variables (ep1,ep2,d,s1,l1,s2,l2), which produces as an output a vector like,

def toFit(ep1,ep2,d,s1,l1,s2,l2)  
…  
a lot of code  
…  
return np.asarray([s0s[0], s0s[1], s0s[2], emi])

Then I implement it in the PyMC3 framework,

def f(ep1 = ep1, ep2 = ep2, d = d, s1 = s1, l1 = l1,s2 = s2, l2 = l2):  
return toFit(ep1,ep2,d,s1,l1,s2,l2)

This function works properly like this,

f(ep1 = 2, ep2 = 4, d = 0.025, s1 = 0.002, l1 = 0.02,s2 = 0.002, l2 = 0.02)  
returning an array([-14.25180297, -1.17028161, -2.21212258, 0.96023043]) as output.

But when I try to define the Deterministic function as,

with model:  
function\_pm = pm.Deterministic(‘s0f’, f())

I get this error,

* * *

ValueError Traceback (most recent call last)  
 in   
1 with model:  
----\> 2 function\_pm = pm.Deterministic(‘s0f’, f())

~\miniconda3\envs\bayes\lib\site-packages\pymc3\model.py in Deterministic(name, var, model)  
1595 “”"  
1596 model = modelcontext(model)  
 → 1597 var = var.copy(model.name\_for(name))  
1598 model.deterministics.append(var)  
1599 model.add\_random\_variable(var)

ValueError: order must be one of ‘C’, ‘F’, ‘A’, or ‘K’ (got ‘s0f’)

There is clearly something wrong, since it is assuming that the ValueOrder is the function name.

The funny thing is that if I just return the last element (‘emi’) or the vector ‘s0s’ there is no error. So, the error is in the stacking of s0s and emi. I tried concatenate, hstack, stack and append from numpy, and I also tried some theano equivalents. Nothing seem to work.

---

<div class="post-metadata">

**Author:** ![verderis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/verderis/32/485_2.png) [@verderis](https://discourse.pymc.io/u/verderis)\
**Post date:** [May 13, 2021, 10:13pm UTC](https://discourse.pymc.io/t/stack-numpy-array-as-output-of-complex-function-produces-valueerror-order-must-be-one-of-c-f-a-or-k-got-s0f/7421/2 "2021-05-13T22:13:57Z")

</div>

I have found a workaround, using tt.set\_subtensor() in a loop to assign output values to an empty array. Painfully slow but it worked.

---

<div class="post-metadata">

**Author:** ![HG1](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hg1/32/1669_2.png) [@HG1](https://discourse.pymc.io/u/HG1)\
**Post date:** [September 28, 2021, 8:46am UTC](https://discourse.pymc.io/t/stack-numpy-array-as-output-of-complex-function-produces-valueerror-order-must-be-one-of-c-f-a-or-k-got-s0f/7421/3 "2021-09-28T08:46:41Z")

</div>

Hi  
I have the same issue.  
Can you show your solution?

Regards Hans

---

<div class="post-metadata">

**Author:** ![verderis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/verderis/32/485_2.png) [@verderis](https://discourse.pymc.io/u/verderis)\
**Post date:** [September 28, 2021, 9:06pm UTC](https://discourse.pymc.io/t/stack-numpy-array-as-output-of-complex-function-produces-valueerror-order-must-be-one-of-c-f-a-or-k-got-s0f/7421/4 "2021-09-28T21:06:43Z")

</div>

Of course!

```auto
a = TT.zeros(n)
for i in range(n):
    a = TT.set_subtensor(a[i], tensor)

```

---

<div class="post-metadata">

**Author:** ![HG1](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hg1/32/1669_2.png) [@HG1](https://discourse.pymc.io/u/HG1)\
**Post date:** [October 1, 2021, 5:33pm UTC](https://discourse.pymc.io/t/stack-numpy-array-as-output-of-complex-function-produces-valueerror-order-must-be-one-of-c-f-a-or-k-got-s0f/7421/5 "2021-10-01T17:33:57Z")

</div>

Hi  
Could you share the complete code?  
What is not clear to me is the pm.Deterministic part.

Thanks anyway  
Regards Hans
