-2

I have input like this:

y=[[array([ 0.12984648,  0.02116148,  0.08041889, ..., -0.11139846,
       -0.0893152 , -0.05336994]), 1], [array([-0.11865588, -0.16726171, -0.06753636, ...,  0.00991138,
       -0.11180532, -0.01146698]), 0] ]

I want to convert it into:

y=[
[[ 0.12984648,  0.02116148,  0.08041889, ..., -0.11139846,
       -0.0893152 , -0.05336994], 1], [[-0.11865588, -0.16726171, -0.06753636, ...,  0.00991138,
       -0.11180532, -0.01146698], 0]
]
Ehsan
  • 12,072
  • 2
  • 20
  • 33
  • 1
    The question is how did you create this? Does each element of y have the same dimension? If so convert it to a numpy array then convert it to list. If Not, you will have to loop through each element to convert everything to a list. Last option will be to use itthe way it is since you can do almost the same thing to the array as to the list – Onyambu Jul 31 '20 at 19:29
  • 1
    Thats waht you want - we solve problems you have - so what problem do you have doing what must be done? [mre]? – Patrick Artner Jul 31 '20 at 19:31

1 Answers1

0

You cannot have non-rectangular arrays. So your only option is to use lists and here is how you convert it to lists:

y = [[i[0].tolist(),i[1]] for i in y]

output:

[[[0.12984648, 0.02116148, 0.08041889, ..., -0.11139846, -0.0893152, -0.05336994], 1], 
 [[-0.11865588, -0.16726171, -0.06753636, ..., 0.00991138, -0.11180532, -0.01146698], 0]]
Ehsan
  • 12,072
  • 2
  • 20
  • 33
  • I am getting this output: IOPub data rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_data_rate_limit`. Current values: NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec) NotebookApp.rate_limit_window=3.0 (secs – harshini sewani Jul 31 '20 at 19:39
  • I am using google colabs and this is happens when I am trying to print y – harshini sewani Jul 31 '20 at 19:41
  • @harshinisewani that is a different issue. You can create a separate question for it. Nonetheless, as error message says, you probably have to set `NotebookApp.iopub_data_rate_limit` value to a higher limit than 1MB/s. That is not the issue with the code above. – Ehsan Jul 31 '20 at 19:41
  • how can I set that value? – harshini sewani Jul 31 '20 at 19:50
  • @harshinisewani Does this https://stackoverflow.com/questions/43490495/how-to-set-notebookapp-iopub-data-rate-limit-and-others-notebookapp-settings-in answer your question? – Ehsan Jul 31 '20 at 19:52