0

PHP:

echo json_encode($temp);
$rtu = shell_exec("C:/Python27/python 123.py ".json_encode($temp));

Python:

import sys, json
import numpy as np
from numpy import matrix
from numpy import array
A=np.matrix(json.loads(sys.argv[1]))
print A
print ("<br/>")
M=A.I
B = np.asarray(M)
print (json.dumps(B.tolist()))

I have this array $temp(29x29) but when I echo its json_encode my first 28 rows are printed correctly (as in {"0":0,"1":0,"2":0...) but the 29th row is printed as [0,0,0..]. Moreover the output $rtu is coming out to be null. Can anyone fix that?

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
abcdxx
  • 207
  • 1
  • 3
  • 12
  • You need to use `escapeshellarg` to keep the special characters in JSON from being processed by the shell. – Barmar Jul 04 '13 at 04:09
  • The reason 29th row is printed as [0,2,4,3... and so on] is that you have not given index to array containing these values [0,2,4,3... and so on]. Give index 0. ({"0":0,"1":0,"2":0... and so on) Here 0 index ["0":] contains the array. – cartina Jul 04 '13 at 04:10
  • How is this different from the question you asked yesterday http://stackoverflow.com/questions/17425426/i-have-to-pass-an-array-from-a-php-file-to-python-file-but-my-code-is-giving-out – Barmar Jul 04 '13 at 04:11
  • @Barmar read the whole ques – abcdxx Jul 04 '13 at 04:27
  • Why there is a need of giving index values were assigned to it in a loop in the same way as the other rows – abcdxx Jul 04 '13 at 04:30
  • escapaeshellarg is not adding anything to it.output still same – abcdxx Jul 04 '13 at 04:31
  • Show us `var_dump($temp)`. – Barmar Jul 04 '13 at 04:33
  • Actually, to keep it manageable, show us `var_dump($temp[0])` and `var_dump($temp[28])` – Barmar Jul 04 '13 at 04:35
  • for var_dump($temp[0])array(29) { [1]=> int(0) [2]=> float(-5.7570523891767) [3]=> float(-5.0428643469491) [4]=> float(-5.6721497447533) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) [12]=> int(0) [13]=> int(0) [14]=> int(0) [15]=> int(0) [16]=> int(0) [17]=> int(0) [18]=> int(0) [19]=> int(0) [20]=> int(0) [21]=> int(0) [22]=> int(0) [23]=> int(0) [24]=> int(0) [25]=> int(0) [26]=> int(0) [27]=> int(0) [28]=> int(0) [0]=> float(33.863370828705) } – abcdxx Jul 04 '13 at 04:50
  • for var_dump($temp[28]): array(29) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(0) [4]=> int(0) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) [12]=> int(0) [13]=> int(0) [14]=> int(0) [15]=> int(0) [16]=> int(0) [17]=> int(0) [18]=> int(0) [19]=> int(0) [20]=> int(0) [21]=> int(0) [22]=> int(0) [23]=> int(0) [24]=> int(0) [25]=> float(-1.659200265472) [26]=> int(0) [27]=> float(-2.2060445621002) [28]=> float(3.8652448275722) } – abcdxx Jul 04 '13 at 04:51

0 Answers0