mapping j function (used defined) over a list - function

I've written my own version of the exponential (^) function which works fine for simple scalars :
3 : '+/ (y&^%!) i.50'
It doesn't work over a list, so I thought of modifying it with "0
3 : '+/ (y"0&^%!) i.50'
This works over a list but gives the wrong answers.
Two questions arise:
1) Given my usage of "0 doesn't work, is there one that does ?
2) If I don't have access to a functional definition like this, what is the best way to apply it to the individual elements of an array ?

You need to apply the rank conjunction "0 over the function you want to map (y&^%!), instead of its argument y:
3 : '+/(y&^%!)"0 i.50'
However, the precision isn't as good as the native ^:
a =: 3 : '+/(y&^%!)"0 i.50' 4 4 $ 10+i.20
b =: ^ 4 4 $ 10+i.20
a = b
1 1 1 1
0 0 0 0
0 0 0 0
0 0 0 0

Related

ValueError; Quantreg with Intercept

I am working with the following dataframe, called test:
y intercept x
0 -1.6168468132687293 1 NA
1 1.5500031232431757 1 NA
2 1.5952617833602785 1 1.5500031232431757
3 1.1390724309357498 1 1.5952617833602785
4 0.9950311340335872 1 1.1390724309357498
5 0.7095780139613861 1 0.9950311340335872
6 0.5962529862944801 1 0.7095780139613861
7 0.6555353674581792 1 0.5962529862944801
8 1.0008751093886736 1 0.6555353674581792
9 1.2648319050758074 1 1.0008751093886736
I am trying to apply the smf.quantreg() function to the dataframe as follows:
import statsmodels.formula.api as smf
Output_pre = smf.quantreg('y ~ intercept + x', test , missing = 'drop')
Output = Output_pre.fit(q=0.25)
The equivalent standard statsmodels.ols() function works just fine. However, applying the smf.quantreg() function yields the following error:
ValueError: operands could not be broadcast together with shapes (3,) (2,)
Why is that so and how do I solve this issue?
I found out myself. By default, the function gives an intercept. Hence the input matrix is not full rank when including a second intercept (two columns are perfectly colinear).

0b01 ^ 0b10 = 0b1 (Google search result)

If I Google search 0b01 ^ 0b10, the result I get back by Google's result widget is 0b1.
Is this a bug? Or am I missing something here?
I'm expecting an answer of ob11, based on these simple rules:
0 ^ 0 = 0
1 ^ 1 = 0
1 ^ 0 = 1
0 ^ 1 = 1
Thank you #harold:
The google result widget interprets ^ as exponentiation.
Took me a while to realize that.

Generate all possible permutations in julia

What I am trying to do is generate all possible permutations of 1 and 0 given a particular sample size. For instance with a sample of n=8 I would like the m = 2^8 = 256 possible permutations, i.e:
I have been doing this in R, but it is very slow. Is there a quick way to do this in the Julia programming language?
These are just the numbers from 0 to 2^k-1, written in binary.
# Strings
k=8
[ bin(n,k) for n in 0:2^k-1 ]
# Arrays
[ [ bit == '1' ? 1 : 0 for bit in bin(n,k) ] for n in 0:2^k-1 ]

Database update weirdness

I am developing a game in Django in which the quantity of rebels updates after a turn change. Rebels are represented as integers from 0 to 100 in the (MySQL) database.
When I save, this happens:
print world.rebels
>>> 0
rebstab = 0
world.rebels += rebstab
world.save()
print world.rebels
>>> 0
However, when I use F() expressions (as I gather I should to prevent race conditions), this happens:
print world.rebels
>>> 0
rebstab = 0
world.rebels = F('rebels') + rebstab
world.save()
print world.rebels
>>> 100
What's going on?
I don't have any experience with using F() objects like this so this answer may not be useful, but having a look at the documentation it mentions:
In order to access the new value that has been saved in this way, the object will need to be reloaded:
reporter = Reporters.objects.get(pk=reporter.pk)
so you may have to actually query the DB again to see the updated value:
print world.rebels
>>> 0
rebstab = 0
world.rebels = F('rebels') + rebstab
world.save()
print World.objects.get(pk=world.pk)
>>> 100
Edit: Also look [at the example where you don't need to pull the objects into memory and can do everythign at the DB level:
World.objects.get(pk=...).update(rebels=F('rebels) + 1)
I just figured out the reason had nothing to do with the F() object itself but rather a conflict with a custom save method. See Django F() objects and custom saves weirdness for a more indepth explanation.

Create line chart from csv file without excel

Suppose i have the following data in csv format :
Time Total Allocated Deallocated
0.00004 0 16 0
0.000516 16 31 0
0.046274 47 4100 0
0.047036 4147 0 31
0.047602 4116 35 0
0.214296 4151 4100 0
0.215109 8251 0 35
i am looking for some kind of software that will allow me to make a line chart of it ( where time column will be the X axis) , i used excel for now , but i am looking for something else,that will allow me to see in greater details .
Any ideas ?
Use Datawrapper. It's very easy and you can publish it on the web or export it to a PNG file.
You can also use R. Here is an example of code to generate a time series plot :
library("ggplot2")
df <- data.frame(date = seq(as.Date("2012-01-01"),as.Date("2012-12-01"), by = "month"), x = rnorm(12))
ggplot(df, aes(x=date, y = x)) + geom_line() + theme_bw()
This is an old question but still: https://plot.ly is also a good site for that kind of stuff.