1

I am recieving some POST data every three seconds (precisely 384 rows). These are stored in list called data. Then I would like to store them in list helper, which would be appended by data after every POST. For now I want to check the data in graph, so I need to convert helper into numpy array, which is called myArr.

data = json.loads(json_data)["data"] #I get some data
helper=[] #Then create list
helper.append(data) # And here I would like to add values to the end
myArr=np.asarray(helper)

self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write("") 


print (len(data))
print(type (data))
print (len(helper))
print(type (helper))
print (len(myArr))
print(type (myArr))
print data

But when I execute the code, the lenghts are not the same:

>>384
>><type 'list'>
>>1
>><type 'list'>
>>1
>><type 'numpy.ndarray'> 

And the list data content looks like this:

[[0.46124267578125, 0.0545654296875, 0.89111328125, 0.0, 0.0, 0.0, 0.0],
[0.46124267578125, 0.0545654296898, 0.89111328125, 0.0, 0.0, 0.0, 0.0],
[0.46124267578125, 0.0545654296875, 0.89111328125, 0.0, 0.0, 0.0, 0.0],
[0.4637451171875, 0.05804443359362, 0.8892822265625, 0.0, 0.0, 0.0, 0.0],
[0.4637451171875, 0.05804443359301, 0.8892822265625, 0.0, 0.0, 0.0, 0.0],
[0.4637451171875, 0.05804443359375, 0.8892822265625, 0.0, 0.0, 0.0, 0.0],
[etc.]]

I think there's just problem with dimensions of lists which I can not figure out.

1
  • 1
    If you want to concatenate lists, you can simply do list_c = list_a + list_b or in your case helper += data Commented Apr 22, 2017 at 14:41

1 Answer 1

0

You have a list to which you append another list, giving you a nested list with one item. Simple demo:

>>> data = [1,2,3]
>>> helper = []
>>> helper.append(data)
>>> helper
[[1, 2, 3]]
>>> len(helper)
1

I could not figure out from your question why you need the helper list at all, but to make a (shallow) copy issue helper = data[:] or helper.extend(data). Since I'm not sure where you are going from here I'll leave this answer at telling you why your helper list has one element, for now.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for answer, I see now, that I am creating some sort of pyramid in 0. index of the list :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.