Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 python3 List to array or string to extract data
#1
Hey,

i am using python 3 and new to python.
i have this list :

([[[32.098659, 34.826334], [32.099361, 34.830506], [32.097026, 34.831574], [32.095502, 34.827881]]],)
This is how i see the value of the var poly using print
and i made sure its of type list. and the numbers represent X and Y on a map.

now i need to split \ make this list like an array to fit this logic :


  p1x,p1y = poly[0]
    for i in range(n+1):
        p2x,p2y = poly[i % n]
        if y > min(p1y,p2y):
             if y <= max(p1y,p2y):
                 if x <= max(p1x,p2x):
                     if p1y != p2y:
                         xinters = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
                     if p1x == p2x or x <= xinters:
                         inside = not inside

        p1x,p1y = p2x,p2y
    return inside
i need somhow to split poly to fit like an array with poly[0] so it can fit this function
but because its a list i get poly[0] as one big string and havent find a way to split it.

i tryied to use :
dataset_list = ''.join(str(poly))
poly = dataset_list.split(']')
it didnt work.
and i get this error
p1x,p1y = poly[0]
ValueError: too many values to unpack (expected 2)

please help me split this list.
thanks!
Quote
#2
what you have is tuple with one element list, that list has one element - list. Now that list has many elements - lists
>>> foo = ([[[32.098659, 34.826334], [32.099361, 34.830506], [32.097026, 34.831574], [32.095502, 34.827881]]],)
>>> type(foo)
<class 'tuple'>
>>> foo[0]
[[[32.098659, 34.826334], [32.099361, 34.830506], [32.097026, 34.831574], [32.095502, 34.827881]]]
>>> type(foo[0])
<class 'list'>
>>> foo[0][0]
[[32.098659, 34.826334], [32.099361, 34.830506], [32.097026, 34.831574], [32.095502, 34.827881]]
>>> type(foo[0][0])
<class 'list'>
>>> foo[0][0][0]
[32.098659, 34.826334]
>>> type(foo[0][0][0])
<class 'list'>
>>> foo[0][0][0][0]
32.098659
>>>
Quote
#3
Just to make things clear:

>>> poly = ([[[32.098659, 34.826334], [32.099361, 34.830506], [32.097026, 34.831574], [32.095502, 34.827881]]],)
>>> type(poly)
tuple
>>> len(poly)
1
>>> type(poly[0])
list
>>> len(poly[0])
1
>>> type(poly[0][0])
list
>>> len(poly[0][0])
4
buran likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Quote
#4
(May-28-2019, 12:39 PM)buran Wrote: what you have is tuple with one element list, that list has one element - list. Now that list has many elements - lists
>>> foo = ([[[32.098659, 34.826334], [32.099361, 34.830506], [32.097026, 34.831574], [32.095502, 34.827881]]],)
>>> type(foo)
<class 'tuple'>
>>> foo[0]
[[[32.098659, 34.826334], [32.099361, 34.830506], [32.097026, 34.831574], [32.095502, 34.827881]]]
>>> type(foo[0])
<class 'list'>
>>> foo[0][0]
[[32.098659, 34.826334], [32.099361, 34.830506], [32.097026, 34.831574], [32.095502, 34.827881]]
>>> type(foo[0][0])
<class 'list'>
>>> foo[0][0][0]
[32.098659, 34.826334]
>>> type(foo[0][0][0])
<class 'list'>
>>> foo[0][0][0][0]
32.098659
>>>

Hey, Thanks for the quick answers, it doesn't work for me from the code, if i do python3 on terminal and doing your commandes it does work but, from the code it doesn't.
maybe its because i forgot to mention i do :
    poly = list(poly)
in another section before that one ?

this is what i get when i run it through test.py code:

    print("POLYYY", poly[0][0][0])
            print(type(poly))

       [1], INF, POLYYY (32.098659,)
       [1], INF, <class 'list'>

Thanks
Quote
#5
show us full code snippet. it looks like you do a lot of unnecessary conversions...
best would be to limit the code snippet to 5-10 lines of code that reproduce the problem.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Issue with creating an array of pixel data for PNG files in Google Colab The_Sarco 1 147 Apr-29-2020, 12:03 AM
Last Post: bowlofred
  Python modules to extract data from a graph? bigmit37 4 9,945 Feb-25-2020, 08:45 PM
Last Post: JohnnyE
  append list to empty array SchroedingersLion 1 244 Feb-02-2020, 05:29 PM
Last Post: SchroedingersLion
  extract first and last 5 elements from given list and generate a new list. Raj_Kumar 1 242 Dec-07-2019, 05:03 PM
Last Post: ichabod801
  extract specific data from a group of json-files ledgreve 3 353 Dec-05-2019, 07:57 PM
Last Post: ndc85430
  Extract email addresses from string and store them in a list oslosurfer 2 269 Nov-24-2019, 03:35 PM
Last Post: oslosurfer
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 545 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  extract version in a string lokesh 2 271 Oct-09-2019, 05:49 AM
Last Post: buran
  How to read a text file into a list or an array musouka 2 722 Oct-07-2019, 01:54 PM
Last Post: musouka
  Most efficient way of reshaping a list-array structure midarq 2 269 Sep-25-2019, 09:32 AM
Last Post: midarq

Forum Jump:


Users browsing this thread: 1 Guest(s)