« first day (2048 days earlier)      last day (2901 days later) » 

7:04 PM
104
Q: How are globals any different from a database?

Mason WheelerI just ran across this old question asking what's so evil about global state, and the top-voted, accepted answer asserts that you can't trust any code that works with global variables, because some other code somewhere else might come along and modify its value and then you don't know what the be...

Really interesting discussion.
 
"A single global is a tragedy; a million globals is a database." -- Joseph Stalin (paraphrased)
23
 
Use PyPy-STM and globals are consistent.
 
@MorganThrapp Note that Python globals aren't as bad as C globals.
 
How so?
 
Well, for one thing, in Python a function effectively has to ask for explicit permission to modify a global. Also, globals in Python only really have module-level scope, although they are also accessible in modules you import them into. In C it's possible for a global to be accessible to any source file in a project that declares it, but unlike in Python that declaration doesn't specify where the global is actually defined.
 
7:19 PM
Makes sense.
 
Air
Cabbage, strangers
 
Cabbage, Austria Air.
 
cabbage
your profile page is...interesting
 
Air
I, tasked with an assignment to develop a small database application, made the inexplicable decision to suggest to the end user that Access might serve the project requirements as well as my original suggestion of MySQL + Python. After two weeks of dealing with the consequences of my temporary insanity, I have come to be whipped soundly for my sins
 
Oh dear lord, why?
Access? Even the name of the database is a filthy lie.
 
7:25 PM
I knew a person called Air once.
 
Air
I am literally Joffrey Lannister Baratheon
 
In college I knew a guy who introduced himself as "sketch". Nice guy.
I assume it wasn't his real name, which was probably "Norbert" or something.
 
sounds pretty sketchy
 
He had a Scene Kid kind of thing going on but didn't have any obvious personality deficiencies.
Maybe it was one of those ironic nicknames like calling a big guy "Tiny"
 
Air
@Kevin you're the one who originally recommended Blindsight, yes?
 
7:31 PM
I think so.
 
Air
I know it was in this room. Anyway - recently read the follow-up, Echopraxia. I really like the cut of the author's jib.
He makes me feel horrible about myself and the world around me in a way that is fantastically entertaining.
 
cbg folks
 
cbg Skyler
 
Mm hmm. His is not a bright and shiny future.
 
quick question what does something like data[1,2,3] mean
 
7:34 PM
Same as data[(1, 2, 3)]
 
It's getting the value from the data object that corresponds to the key (1,2,3).
Probably data is a dict, or possibly an N-dimensional array coming from a third party library such as numpy
 
@vaultah is that basically saying something like data[1][2][3]
 
unless data is a numpy.array with dimensionality 3, in which case 1, 2, and 3 talk about the corresponding axes
 
numpy, but not sure if ndarray
im still new to numpy, im using loadtext to pull some data
 
I just edited my last statement (nd array)
 
7:37 PM
is there a concise notation to return an array such that you return [data[i],data[j],data[k]] for any i,j,k
 
?
data[1:4]?
 
well for any arbitrary values
ill fix that
 
data[i1:i2+1]
 
[data[x] for x in my_arbitrary_value_list]
 
@Kevin nooooooooo
 
Air
7:38 PM
@AndrasDeak That only has two arbitrary values, not three
 
why not?
 
data[my_arbitrary_value_list]
numpy ^
 
so would a value list be something like
(i,j,k)
 
I seriously don't understand your question
 
No, (i, j, k) is a tuple.
 
7:39 PM
please imagine yourself in my place and rephrase
 
Air
Is a list like a tuple? Sure, they're containers
 
I knew I should have named it my_arbitrary_value_iterable
 
also, go ahead and try whatever comes to your mind in python
 
NumPy handles tuples differently, by necessity.
 
@Kevin I don't think generators and files work
 
7:40 PM
absolutely ^. Even try importing antigravity
 
Air
brb, renaming the surrogate key in this table KevinsArbitraryValueIterable
 
lists, arrays, maybe tuples OK
 
a generator that eventually finishes would work, why not
 
because I don't know how numpy's implemented:)
and I'm lazy to look at the help or try myself
 
data[(i, j, k)] is equivalent to data[i, j, k], trying to specify single indices along three axes. It requires an at least 3D array.
data[[i, j, k]] accesses data[i], data[j], and data[k].
 
Air
7:42 PM
Any lurkers should read this entire conversation with Well, in numpy... prepended to each message
 
Air
Neat trick for those playing the home game with dicts, if you make your keys namedtuples instead of tuples, you're less likely to be the eventual subject of a legacy maintenance revenge killing
Though how much less, one cannot know
 
@user2357112 so now lets say instead i have a 2D array with a lot of elements, where I need to make a 3-tuple from [[need 3 of the 8 elements in each of these],[],[],...]
basically I have rows with 8 coordinates and im iterating over each of the rows to pull 3 of those coordinates
is there a concise/standard way i should do this in numpy
 
Apr 27 at 14:53, by davidism
Because "use numpy" is the Python equivalent of "use jQuery".
 
import numpy as $
 
Air
7:45 PM
@Skyler How about instead of "let's say I have blah blah foo bar" you just post sample data so we can take advantage of this wonderful shared language called Python
 
import numpy as dollar_sign might work better
 
In [9]: A[(x for x in [0,2])].shape
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-9-6ea1ffb47816> in <module>()
----> 1 A[(x for x in [0,2])].shape

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
 
I thought we were referring to the iterable in the list comprehension other-kevin made
 
I see 12 columns, not 8.
 
7:48 PM
so that is data
is there a concise way of doing [data[1][2],data[1][3],data[1][5]]
basically that would mean [-2.87489179e+00 -2.60000000e+00 0.00000000e+00] for example
 
Air
If the first dimension is always going to be the same, you can shorten it a bit... if only the second dimension is arbitrary
 
@Air yea
 
You can do data[:, [2, 3, 5]] to pull out those columns of data, but the syntax is misleading. It won't do what you expect if you try to generalize it.
If you're iterating row by row, you can do row[[2, 3, 5]]. You usually shouldn't be iterating over a NumPy array, though.
 
8:06 PM
@user2357112 how would one effectively use numpy for the record
if you dont iterate over it
here im just doing a relatively simple application, I have a graphing application that draws line between coordinates
so i have to call that function iteratively to do the drawing, but what would you normally do with numpy?
 
Usually, you should be using operations that work on whole arrays at once.
 
8:40 PM
@user2357112 you can also use fancy indexing, right? data[:, [2, 3, 5]] vs data[:, np.array([2, 3, 5])]
the latter would generalize unless I'm mistaken
In [11]: np.random.rand(3,4,5)[:,np.array([0,1,1]),np.array([2,3,4])].shape
Out[11]: (3, 3)
wait, it does the same with a list...
nevermind, I forgot again how this works
 
 
1 hour later…
10:08 PM
hey just wondering why I'm getting an error in my code def create_tree_from_nested_list(t):
if not t:
return None

bt = RefBinaryTree([0])
bt.set_left(create_tree_from_nested_list(t[1]))
bt.set_right(create_tree_from_nested_list(t[2]))
return bt This is the error I'm getting bt = RefBinaryTree(t[0])
TypeError: 'int' object is not subscriptable
 
did you check to see what t is? the error is saying that you are trying to treat an int type as a list
print(type(t))
 
yeah i get this <class 'list'>
<class 'int'>
any way of fixing it ?
 
use something other than an int to index into:P
 
:)
 
hmm yeah just trying to figure out what to reference it to
because im trying to get this nested_list = [2 ,31, 27, None, None, None, 5, None, 1, 7, None, None, None] to return a tree haha
thanks though guys !
 
10:18 PM
but that's not a nested list
 
jesus -.- hold on i pasted the wrong thing
I'm supposed to create a function that returns a tree with the list values laid out in level order, values of "None" mean that there is no
value at that spot.
 
and is t in the context of your code each iteration of the list?
 
yeah i think i messed up my code sorry guys
 
good luck!
 
10:49 PM
Has this already made the rounds here? googleresearch.blogspot.com/2016/05/…
Parsey McParseface, that is
I just saw it today in my O'Reilly newsletter
 
I haven't seen it posted here...but I haven't been online mostly today
interesting
 
Air
11:12 PM
@PaulMcGuire I love the name but I also love the blog post - very cool stuff
 
We're getting closer to the robot apocalypse step by step:P
 

« first day (2048 days earlier)      last day (2901 days later) »