Multidimensional array model Django
NickName:that_one_nerdy_guy Ask DateTime:2018-04-17T21:59:36

Multidimensional array model Django

TLDR: trying to send a 2d array with django rest and it fails, why?

So here is my situation. I am creating a ingest tool to take in data, that is created by someone else. Part of this data is a 2d array or a list of lists, whatever strikes your fancy. Something like this being a list of lists of floats in this case Data = [[1,2,3,4,5,6],[1,2,3,4,5,6]] I am trying to use a Django rest service to do this because thats what i have been using for everything else i have done. Anyway this data type is given to me in a json format along with other datatypes Which i will show as well. On the model side of this i have a model of the main dataType that data would go into which looks like this

class dataType(models.Model):
  data = ArrayField(ArrayField(models.FloatField(blank=True, null=True),
                              null=True), null=True)  
  data1 = ArrayField(models.FloatField(blank=True, null=True),
                               null=True)
  ...
  other data

Now data is the one i am having issues with. data1 will work fine as long as its just singular dimensional array(list). when i run the code with this i get an error saying this Expected a list of items but got type \\"str\\"."]}' even though i am sending it a list. It gets a 400 for this vary reason. Here is what the json code would look like.

"dataType": [
  {
    "otherData": stuff                                
    "data": [
      [1, 2, 3, 4, 5, 6],
      [1, 2, 3, 4, 5, 6],
      [1, 2, 3, 4, 5, 6],
      [1, 2, 3, 4, 5, 6],
      [1, 2, 3, 4, 5, 6],
      [1, 2, 3, 4, 5, 6]
    ]
  }
]

Just as side not before anyone asks, no i cannot change the data from a 2d array, it has to stay like that, if it were up to me i would change it.

Another side note, i have attempted using just one arrayfield like data1 with the 2d array stuff, it returns back a 201 BUT on the rest side when i go to localhost:8000/api/v3/dataType it gives me a 500 error and complains and says something along the lines of looking for a string or float but received a list.

UPDATE: concerning the last side note, i have found this does work but it converts my 2d array into one giant single array so this is still not what i want, i need my 2d array to stay as a 2d array.

Copyright Notice:Content Author:「that_one_nerdy_guy」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49880159/multidimensional-array-model-django

More about “Multidimensional array model Django” related questions

create a multidimensional array field in Django model

I get multidimensional arrays must-have array expressions with matching dimensions error from Django when I try to insert data into my model, below is my model and the data format i have effect =

Show Detail

Multidimensional array model Django

TLDR: trying to send a 2d array with django rest and it fails, why? So here is my situation. I am creating a ingest tool to take in data, that is created by someone else. Part of this data is a 2d...

Show Detail

Working with a Multidimensional Array as a CoreML Model output

I have trained an object detection CoreML model using Microsoft's customvision.ai service. I exported it to use in my app to recognize certain objects in real time using the camera. However the Cor...

Show Detail

How to access multidimensional array using django templates in html page

I have a multidimensional array in php page like this: $comment=Array ( [655436] => [655435] => Array ( [id] => 5864928 [shortmessage] => rytrh...

Show Detail

Is there a multidimensional database model?

What is the essential difference between relational and multidimensional databases? I just don't get it. The arguments I find on the Internet do not make it clear to me, in fact they mostly do not...

Show Detail

Mathematical representation of a multidimensional array

This might me a ridiculous question. I created mathematical model using Python and I know that I started this from the end, but I need write mathematical equations for the documentation. The equati...

Show Detail

Jquery serialize and model bind multidimensional array

I'm trying to Model bind a multidimensional array using ajax through MVC. My single Dimension array maps fine the only thing that doesn't map is the multidimensional. I'm grabbing the data using ...

Show Detail

Search in multidimensional array

On my website I have a list of products generated through a foreach and creates a multidimensional array. The array is this: (Short) http://k44.kn3.net/73194E0F9.jpg I need to search within this

Show Detail

Convert array of arrays into multidimensional array in Typescript

I'm trying to convert an array of arrays that is requested from a http service. I have the following code below: This is the array from the http service that will have a number of arrays: [object...

Show Detail

How to access multidimensional dictionary on Django template

I am trying to access a multidimensional dictionary in a Django template. I am able to view first level keys, but since second level keys I cannot see anything. In example dictionary is composed in...

Show Detail