[Tutor] pointers or references to variables or sub-sets of variables query.
Hi all. In C, you can use pointers to reference variables, arrays, ETC. In python, I do not recall anything specifically that refers to such a capability. What I want to do is: I want to create different data structures such as dictionaries which contain specific list elements based upon specific keys. The original data structure could look like: Data = [ ['2019-01-19','Fred Flintstone',23], ['2019-02-01','Scooby doo', 99] ] The above structure does have 100's of elements. I want to reference specific lists within the above structure. Using the only method I know how: Category = {'under-50':[data[0]], 'over-50':[data[1]]} If I understand things correctly with Python. The above will copy the value into the list within the key. Not the memory address of the nested list I am referencing. I am using a list within the key to permit multiple references to different nested lists from the original data structure. The end result of the structure for the dict could look like this (using example, not real output) Category['under-50'] = [ List1 pointer, List22 pointer, List52 pointer] I hope the above makes sense. How can this be done? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Neutral Networks
Hi, I hope this email finds you well. I am writing to get help with the AI program I am currently working on. I have a python program for the project which is about developing an AI program to identify persons. The program I have identities the first person. It is not able to identify the 2nd person. When we run it, it is not even showing an error. I need someone to look at it and let me know me the issue. I can share the source code. Thank you! Best regards, Rashmi ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pointers or references to variables or sub-sets of variables query.
On 07/07/2019 03:39, mhysnm1...@gmail.com wrote: > In C, you can use pointers to reference variables, arrays, ETC. In python, I > do not recall anything specifically that refers to such a capability. In Python a variable is a name that refers to an object. Many names can refer to the same object. So in that respect Python variables are more like pointers than regular C variables which are a named location in memory. > Data = [ > ['2019-01-19','Fred Flintstone',23], > ['2019-02-01','Scooby doo', 99] > ] > > > Category = {'under-50':[data[0]], 'over-50':[data[1]]} > > If I understand things correctly with Python. The above will copy the value > into the list within the key. No, that is not correct. It will create a reference to the same data object So Category['under-50'][0] and Data[0] will both reference the same list object. Modifying the data through either variable will affect both because it will be the same list being modified. > Not the memory address of the nested list I am > referencing. It is best to forget all about memory addresses when thinking about Python. They are irrelevant for the most part.. > Category['under-50'] = [ List1 pointer, List22 pointer, List52 pointer] That is exactly what happens in Python, as standard. The usual issue that people have with this is that they modify the data in one place and are surprised to discover it has been modified elsewhere too. If that is a problem then you must explicitly create a copy. But the behaviour that you apparently want is the default. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Neutral Networks
On 07/07/2019 03:49, Rashmi Vimalendran wrote: > I have a python program for the project which is about developing an AI > program to identify persons. The program I have identities the first > person. It is not able to identify the 2nd person. When we run it, it is > not even showing an error. I need someone to look at it and let me know me > the issue. I can share the source code. We will need to see code. If it is less than say 100 lines post it in the body of your mail(not an attachment!) and if it is longer put it in a pastebin web site and send a link. Send us some sample data too so we can see the structures. A little bit more detail on what exactly the output looks like and how you identified the problem would help. Finally, tell us the OS, Python version and any third party libraries you are using - SciPy, Rpy, etc. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Neutral Networks
perhaps something needs to be cleared? What do mean by identify, as in recognition or detection? what kind of network? What NN framework (Keras, tenser flow,caffee etc.) Are both people in the same frame? > Den 7. jul. 2019 kl. 04.49 skrev Rashmi Vimalendran > : > > Hi, > > I hope this email finds you well. I am writing to get help with the AI > program I am currently working on. > > I have a python program for the project which is about developing an AI > program to identify persons. The program I have identities the first > person. It is not able to identify the 2nd person. When we run it, it is > not even showing an error. I need someone to look at it and let me know me > the issue. I can share the source code. > > Thank you! > > Best regards, > Rashmi > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pointers or references to variables or sub-sets of variables query.
First-off, it has to be said that "100's of elements" suggests using an RDBMS - particularly if 'age' (eg 23 and 99) is not the only likely selection mechanism. On 7/07/19 2:39 PM, mhysnm1...@gmail.com wrote: Hi all. In C, you can use pointers to reference variables, arrays, ETC. In python, I do not recall anything specifically that refers to such a capability. What I want to do is: Just because C has a construct does not imply that it does, nor even should, exist in another language! You're using Python because it is 'better', right? You are correct, Python does not use "pointers", and (a personal comment) I for one don't miss them and their many 'gotchas', eg out-by-one errors, preferring Python's constructs, eg for-each. That said, Python's sequences (data structures, eg strings and lists) do offer indices, slicing, and striding. So, it is quite possible to (relatively) address the first item in a list as list_item[ 0 ]. You can read about these (and many other delights) in the docs... I want to create different data structures such as dictionaries which contain specific list elements based upon specific keys. The original data structure could look like: Data = [ ['2019-01-19','Fred Flintstone',23], ['2019-02-01','Scooby doo', 99] ] Warning1: seem to be missing any identification of the "key" Warning2: the intro text talked about "dictionaries" (the correct word) but the code-snippet is describing nested lists The above structure does have 100's of elements. I want to reference specific lists within the above structure. Using the only method I know how: Category = {'under-50':[data[0]], 'over-50':[data[1]]} If I understand things correctly with Python. The above will copy the value into the list within the key. Not the memory address of the nested list I am referencing. I am using a list within the key to permit multiple references to different nested lists from the original data structure. The end result of the structure for the dict could look like this (using example, not real output) Category['under-50'] = [ List1 pointer, List22 pointer, List52 pointer] I hope the above makes sense. How can this be done? I hope I've understood the description! One option would be to follow your line of thinking by turning the first data-structure into a dictionary (key-value) pairs, where the key is the character's age and the value is the inner list structure, previously outlined: { 23: ['2019-01-19','Fred Flintstone',23], 99: ['2019-02-01','Scooby doo', 99] } Then it would be possible to maintain the two lists, each containing keys for the relevant dict-elements: under_50 = [ 23 ] over_50 = [ 99 ] However, this would require that only one character be listed at a given age (dict keys must be unique), so another key might be a better choice! Another data structure you might consider is a "linked list". -- Regards =dn ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pointers or references to variables or sub-sets of variables query.
On 07/07/2019 09:19, David L Neil wrote: > First-off, it has to be said that "100's of elements" suggests using an > RDBMS - particularly if 'age' (eg 23 and 99) is not the only likely > selection mechanism. Multiple selection mechanisms might suggest an RDBMS but hundreds of items is chickenfeed and an RDBMS would be overkill for such small numbers, if volume was the only criteria. Millions of items would certainly warrant such an approach but nowadays holding 10's of thousands of items in memory is entirely reasonable. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pointers or references to variables or sub-sets of variables query.
On 7/6/19 8:39 PM, mhysnm1...@gmail.com wrote: > Hi all. > > In C, you can use pointers to reference variables, arrays, ETC. In python, I > do not recall anything specifically that refers to such a capability. What I > want to do is: > > I want to create different data structures such as dictionaries which > contain specific list elements based upon specific keys. The original data > structure could look like: > > Data = [ > ['2019-01-19','Fred Flintstone',23], > ['2019-02-01','Scooby doo', 99] > ] > > The above structure does have 100's of elements. I want to reference > specific lists within the above structure. Using the only method I know how: > > Category = {'under-50':[data[0]], 'over-50':[data[1]]} > > If I understand things correctly with Python. The above will copy the value > into the list within the key. Not the memory address of the nested list I am > referencing. I am using a list within the key to permit multiple references > to different nested lists from the original data structure. The end result > of the structure for the dict could look like this (using example, not real > output) > > Category['under-50'] = [ List1 pointer, List22 pointer, List52 pointer] > > I hope the above makes sense. How can this be done? It's easy enough to convince yourself that what Alan said is true. You can, for example, use the id function to show this: https://docs.python.org/3/library/functions.html#id # identity of 0'th element of Data: print(id(Data[0])) # identity of the list that is the value of 'under-50' key: print(id(Category['under-50'])) # identity of 0'th element of that list: print(id(Category['under-50'][0]) the first and third should be the same, showing you that's the same object referred to by those two places. Again, like Python's "variables", these are just references to objects. As in: item = Data[0] print(id(item), id(Data[0])) (note: id() is handy for explorations, especially interactive ones, but isn't terribly useful for production code. don't attach any meaning to the value returned by id() other than "unique" - different Pythons famously generate different id values, something that's been known to confuse people doing experiments in, for example, PyPy) Since you turned up here you sometimes also get free unasked-for advice: I know this was a toy fragment just to explain the concept you're getting at, but you'll normally want to build your design in a way that minimizes "magic". Using numbered indices into an array-like structure is one of those bits of magic that raises flags. To refer to Fred's age, you could end up with Data[0][2]. That would be pretty ugly, and worse, hard to remember what it meant. Try to seek ways you can give meaningful names to things. We can make suggestions if that's of interest (I don't want to belabor the point). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pointers or references to variables or sub-sets of variables query.
On 8/07/19 2:48 AM, Alan Gauld via Tutor wrote: On 07/07/2019 09:19, David L Neil wrote: First-off, it has to be said that "100's of elements" suggests using an RDBMS - particularly if 'age' (eg 23 and 99) is not the only likely selection mechanism. Multiple selection mechanisms might suggest an RDBMS but hundreds of items is chickenfeed and an RDBMS would be overkill for such small numbers, if volume was the only criteria. Millions of items would certainly warrant such an approach but nowadays holding 10's of thousands of items in memory is entirely reasonable. Assuming plentiful RAM: agreed. (However, some of us grew-up at a time when RAM was expensive and even in our relaxed state, such 'costs' still impinge on our consciousness - also, in another thread (here?Python list) we had someone frustrated about using an MS-Vista 'powered' machine and limited to 32-bits. We don't know the OP's circumstances. That said, loading an RDBMS, if (s)he doesn't already have one, is...) As you point-out, with memory more-commonly available, I've obtained significant speed improvements by moving relatively small, and particularly temporary, DB tables into MySQL's MEMORY storage (and with almost zero code-change/risk)! (so, it IS possible to teach old dogs new tricks) The key justification for moving to RDBMS would be "not the only selection mechanism". Whereas a Python dictionary (hash) offers speedy access to data based upon a single index, it is hard to beat the bug- and time-saving facility of a DB managing multiple indices/indexes. (appreciating that I have no difficulty moving from (Python) procedural programming to (SQL) declarative, but many of our colleagues hate such, and with a passion) So, using the OP's data-example, and assuming the 'columns' to be perhaps employment_date, name, and age; respectively: ['2019-01-19','Fred Flintstone',23], ['2019-02-01','Scooby doo', 99] - which Python (and pythonic - per OP's theme) structures and methods offer a relatively bug-unlikely solution to holding *multiple* indices into a base list (or other collection)? (alternately, maybe we should wait for the OP, and allow opportunity to complete the homework first?) (NB this may be veering OT, if the OP requires only the single access method, such as that illustrated earlier) -- Regards =dn ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pointers or references to variables or sub-sets of variables query.
On 07/07/2019 20:54, David L Neil wrote: > (However, some of us grew-up at a time when RAM was expensive and even > in our relaxed state, such 'costs' still impinge on our consciousness - Indeed, my first computer was at the local university and had 64KB. My second computer was a Sinclair ZX81 (Timex in the USA?) with 16K My third, a CP/M machine with 64K and 256K RAM disk and dual floppies - such luxury! :-) So I agree, it is hard to get out of that mode of thinking. But today the minimum RAM is typically 4GB or more. My desktop boxes all have 16GB and even my ancient Netbook has 4G. My 20 year old iBook has 640M and even that is enough to run Python with many thousands of data objects instantiated. > particularly temporary, DB tables into MySQL's MEMORY storage (and with > almost zero code-change/risk)! Yes, I use SQLite's MEMORY facility reguilarly. Not for managing high volumes but where I need flexible search capability. A SQL SELECT statement is much more flexible and faster than any Python search I could cobble together. > (appreciating that I have no difficulty moving from (Python) procedural > programming to (SQL) declarative, but many of our colleagues hate such, > and with a passion) Yes, I've never quite understood why some programmers are reluctant to use SQL. For complex structured data it is by far the simplest approach and usually very efficient, especially with big volumes. But simple searches on small datasets are easier (or as easy) in native Python. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor