简体   繁体   中英

Sending numpy array over socket and retrieving it in java

Basically I want to send the output of Decision tree classifier over socket and get the output in java. I want to predict disease from symptoms. I'll send my sample test vector of symptoms from java through socket and want to get the predicted disease from python.

`dt = DecisionTreeClassifier()
clf_dt=dt.fit(x,y)
output=clf_dt.predict(sym)
print(output) #prints ['Fungal infection']`

Now I want to send this "Fungal infection" through socket and get it in java.

`data_string = pickle.dumps(output)
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) 
s.bind(("localhost",9000)) 
s.listen(10)
connection, address = s.accept()
message             = connection.recv(1024)
print ("Got: {0}".format(message))
connection.send(data_string) #PROBLEM is here.I can't retrieve this in 
java
connection.close()`

Thanks...

I have solved it myself. tostring() is returning bytes. np.array2string(x) returned me a str object which I can pass through socket

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM