quant

1

votes
4

answer
59

views

How do I quickly find the last number of elements matching some criterion in numpy?

Suppose I have some array: x = numpy.array([1, 2, 3, 4, 5, 1, 1, 1]) And I want to find the number of consecutive 1s at the end of the array. One way to do this is with a loop: i = len(x) - 1 while x[i] == 1: i = i - 1 Now I can look at i and work out the number of 1s in the back of x. However, in m...
quant
1

votes
1

answer
65

views

How to read a csv file, which has double quotes next to commas

I have a csv file that its rows look like this q4_1,'blabla,bla',new_label q4_2,alb,new_label2 and I would like to read it in a pandas data.frame that will look like this import pandas as pd pd.DataFrame({'col1' : ['q4_1','q4_2'], 'col2' : ['blabla,bla','alb'], 'col3' : ['new_label','new_label2']})...
quant
1

votes
0

answer
48

views

WSL terminal forgets to update and loses focus

I'm trying to use the WSL console in Windows 10 for some development work, but I find that often running processes will simply appear to have hung, but when I send a keystroke to the terminal it will update back to the bash terminal (as if had completed all along but hadn't updated). Also, I'm findi...
quant
1

votes
4

answer
2.8k

views

Factory method returning an concrete instantiation of a C++ template class

I have a class template class StaticVector { // stuff }; How can I declare and define in this class a static factory method returning a StaticVector object, sth like StaticVector create3dVec(double x1, double x2, double x2); ?
quant_dev
4

votes
1

answer
42

views

How to do outer merge of two dataframes for which column values are within a certain range?

This is followup question of this I have two dataframes: print df_1 timestamp A B 0 2016-05-15 0.020228 0.026572 1 2016-05-15 0.057780 0.175499 2 2016-05-15 0.098808 0.620986 3 2016-05-17 0.158789 1.014819 4 2016-05-17 0.038129 2.384590 5 2018-05-17 0....
quant
1

votes
3

answer
487

views

How to model N-to-N relationships in XML without duplicating data or introducing string handles?

I am trying to achieve an XML structure equivalent to this: Adam Foo Bar Eve Foo Lizzie Bar but without duplicating the tag contents. How can I introduce links between projects and workers in a way which would be validated by the parser and what would the required .xsd file look like?
quant_dev
1

votes
1

answer
1.7k

views

InvalidArgumentException: The service definition “security.encoder_factory.responses” does not exist

I have a really strange error in a symfony 2 installation. Everything worked fine until I suddenly ran into this error. The cache cannot be cleared because of the error, which is also preventing me from checking/updating dependencies with Composer. InvalidArgumentException: The service definition...
Quant
1

votes
1

answer
235

views

How do I most efficiently perform collision detection on a group of spheres

Suppose I have a CPU with several cores, on which I want to find which spheres are touching. Any set of spheres where each sphere is connected (ie. they're all touching at least one of the spheres in the set) is called a 'group' and is to be organized into a vector called, in the example below, 'gro...
quant
1

votes
1

answer
84

views

multilingual formatting of date and time in django

In a multilingual Django project, I want to display datefields in different formats, depending on the localization. Inspired by the example given in the Django documentation on Translation, I would like to use something like def my_view(request, my_date): output = _('Today is %(month)s %(day)s.') %...
Quant Metropolis
1

votes
1

answer
36

views

How do I count the number of times a keyword appears for each section of a table?

Suppose I have a table of phrases organised by some category code: category phrase 0 'hello bye' 0 'hello no' 1 'hello bye' 1 'yes no' 2 'hello bye' Then I want a table that counts the occurrence of each keyword per section: category keyword...
quant
1

votes
1

answer
305

views

How do I print out a comma multiple times using Boost Preprocessor

I need to use a variadic macro to expand to multiple variations of a class. Since they need to have different names based on the macro input I can't simply use templates. The problem is that I can't expand the comma (,) symbol, and my class has functions which take multiple parameters (for which I n...
quant
1

votes
1

answer
538

views

How can freeglut probe whether or not an X11 server is available?

I have a program which can display data graphically using freeglut, which is nice but not essential. I use putty a lot to edit and compile my program on a debian server at home but when I try to run the binary from within putty I get this message: freeglut (./a.out): failed to open display '' Now I...
quant
1

votes
1

answer
48

views

How do I make my branch like another branch while making the changes as a single commit?

Suppose I have a master branch and a feature branch. feature is severely outdated and I now want to make it exactly like master, but I want all changes made to feature that were required in order to complete the 'merge' to appear in a single commit. First I tried this: git checkout feature git merge...
quant
1

votes
1

answer
79

views

How do I bring a single function into the current namespace?

Suppose I want to use the std::max function in my namespace A. How would I do this? namespace A { void fun() { double x = std::max(5.0, 1.0); // I don't want to have to write the std:: } void fun() { using namespace std; double x = max(5.0, 1.0); // I don't want to have to use the using directive to...
quant
1

votes
1

answer
171

views

In boost MPL, how do I check if an operation worked as intended?

Normally when I write code, I frequently check that what I am doing works but using some sort of assertion operation: std::vector a(1, 1); std::vector b = {1}; assert(a == b); // this either works, or breaks in a helpful manner How do I achieve this in boost mpl? I'm currently trying to generate a v...
quant
1

votes
1

answer
58

views

Variable amount of params express js

I am trying to define a route in express js that takes an unknown amount N of parameters. It should match the following routes, capturing all digit groups: /scope /scope/1/12 /scope/1/12/123 etc. I wrote a regex for the matching of the n-amount of numbers, as follows: /(?:\/?(\d+)\/?)/g The global...
Quant
1

votes
1

answer
30

views

How do I separate test types with the template extern keywords?

Suppose I have some type X which is templated on T: // hpp file template struct X { int Get(); }; extern template X; // cpp file template int X::Get() { return T::Get(); } template X; The type T might be a random number generator in a production environment (TraitsType), but for the sake of unit t...
quant
1

votes
1

answer
99

views

How do I remove a file in my root directory?

I tried to create a directory /data as a mount point but that failed for other reasons, now I've got a weird file/data thing in my root directory that just won't die: [email protected]:~$ sudo ls /data ls: cannot access /data: Transport endpoint is not connected [email protected]:~$ sudo rm -rf /data rm: cannot remove...
quant
1

votes
1

answer
39

views

How to use subdirectories with Ruffus pipelines

The Ruffus pipeline documentation seems to assume that one's code and data are in the same directory. All the examples have input and output file specifiers without any relative paths. How should one modify the syntax below if, say, the files to be transformed are not in the current directory? @tran...
Quant
1

votes
1

answer
351

views

How can I inform a thread running libevent that it should take some action?

I am using libevent in a backend thread to run hiredis and subscribe to a remote redis database. The subscription works superbly using the simple examples from another SO question: Hiredis waiting for message However, in order to avoid race conditions it is not trivial to add subscriptions from the...
quant
1

votes
2

answer
531

views

Save a Struct Vector into a Tab delimited Text File

I'm reading a 2 to 4 gb .txt file and then I manipulate some of the data and want to save my struct vector as a tab delimited .txt file. I read some of the other questions but still not clear to me how I'm going to do it in my program. So my question is: How to save the Input vector results as a ta...
Quant Invest
1

votes
1

answer
44

views

How do I use a User Defined Type in a function?

The following trivial example doesn't work: Public Type MyType a As Double b As Integer End Type Function Test() As Variant Dim x As MyType Test = 2 End Function Compile Error: User-defined type not defined How do I 'define' the type?
quant
1

votes
2

answer
499

views

How do I use On Error GoTo?

I'm lead to believe that the vba IDE doesn't allow proper breaking on errors. I asked a question on how to identify runtime errors here: How do I break on errors? The solution / workaround seems to be to use On Error GoTo ErrorHandler or similar. I'm trying to make that work but haven't had much suc...
quant
1

votes
1

answer
50

views

How can I require thread-safety of parameters in an interface?

Suppose I have some interface that takes some set of numbers foo and performs some permutation bar on them: class Interface { public: virtual std::vector PerformBar(const std::vector& foo) = 0; virtual void SetBar(std::function&& func) = 0; }; If the implementation were single-threaded, there would...
quant
1

votes
3

answer
89

views

How to write CSV with per-variable counts of a data.table?

Assuming I have a data table, td, with dimensions 1000x4, with column names x1,x2,x3,x4. If I do td[,.N,x1] I will get the counts for each value of the x1 variable. What I would like to do, is to write all these values in a csv in one go,below each other, so I try x
quant
1

votes
1

answer
29

views

linking table numbers between power point and excel

I am trying to create a presentation file which will contain many tables. These tables though might change. So, I would like to know if there is there a way to link the numbers of a table from an excel file, with the numbers of a table in a powerpoint slide ?
quant
1

votes
1

answer
386

views

count and order in sql at ms-access

I have a table (called Tweets) in ms-access that looks like this text screenName lala user1 la user2 lal user3 lalala user1 l user1 a user4 I would like to have in the end a table, that will contain the number of text per user. The column with the number of te...
quant
1

votes
3

answer
2.8k

views

Calling the Firefox webdriver in python

I'm using Debian 9 Stretch and Pycharm IDE and trying to learn web-scramping; I installed the Selenium package simply by running: pip install selenium and the Firefox webdriver by running: wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz tar -x...
Quant.Pi
1

votes
1

answer
32

views

How to change column order (sort) in pandastic way?

I have a dataframe with header that is list of 'string-integers': import pandas as pd d = {'1': [1, 2], '7': [3, 4], '3': [3, 4], '5': [2, 7]} df = pd.DataFrame(data=d) 1 3 5 7 0 1 3 2 3 1 2 4 7 4 This code change order of column (sort): cols = df.columns.tolist() cols = [int(x) for x in...
Quant Christo
1

votes
1

answer
22

views

Summing columns according to pattern in column names

Lets start with very simplified abstract example, I hava a dataframe like this: import pandas as pd d = {'1-A': [1, 2], '1-B': [3, 4], '2-A': [3, 4], '5-B': [2, 7]} df = pd.DataFrame(data=d) 1-A 1-B 2-A 5-B 0 1 3 3 2 1 2 4 4 7 I'm looking for elegant pandastic solution to...
Quant Christo
1

votes
1

answer
256

views

How do I inspect the contents of tf.estimator.inputs.numpy_input_fn?

I want to train my tensorflow graph over a set of data repeatedly, and I think tf.estimator.inputs.numpy_input_fn might be what I'm looking for. I find the distinction between batch sizes, repeats, epochs and iterators to be incredibly confusing, so I started trying to inspect the contents of my dat...
quant
1

votes
1

answer
111

views

how to order the stacked bar using plotnine

I have the following dataframe import pandas as pd from plotnine import * df = pd.DataFrame({ 'variable': ['gender', 'gender', 'age', 'age', 'age', 'income', 'income', 'income', 'income'], 'category': ['Female', 'Male', '1-24', '25-54', '55+', 'Lo', 'Lo-Med', 'Med', 'High'], 'value': [60, 40, 50, 30...
quant
1

votes
1

answer
1.5k

views

How do I serialize a class containing pointers to primitives?

I am trying to use boost's functionality for serializing pointers to primitives (so that I don't have to de-reference and do a deep store myself). However, I get a pile of errors when I try to do it. Here is a simple example of a class that is supposed to contain save and load methods which write an...
quant
1

votes
2

answer
106

views

How do I keep the result of an operation from a conditional? [duplicate]

This question already has an answer here: C++, variable declaration in 'if' expression 8 answers Ok that title is bad, please feel free to suggest something better, I just don't know what to call it. Suppose I have an object a, and I want to assign some value to it, check that this value meets some...
quant
1

votes
1

answer
361

views

How do I limit project-wide search/replace to my own files only?

I have included the boost libraries in my project, and when I do a search/replace (ctrl+f) and choose Current Project Visual Studio 2013 looks through and replaces matches in my own files (intended) and every boost header and source file (not intended). In Visual Studio 2012 I never had this problem...
quant
1

votes
2

answer
297

views

can I pass information to function-pointer callbacks without using globals?

I am going to use an example with which I am having trouble with, but I will try to keep the topic as generic as possible. I have a function which takes a parameter of type void (*)(), which I want to bind from another function taking input parameters using std::bind. Can this be done? Below is my e...
quant
1

votes
1

answer
428

views

will array_view.synchronize_asynch wait for parallel_for_each completion?

If I have a concurrency::array_view being operated on in a concurrency::parallel_for_each loop, my understanding is that I can continue other tasks on the CPU while the loop is executing: using namespace Concurrency; array_view av; parallel_for_each(extent(number),[=](index idx) { // do some intense...
quant
1

votes
1

answer
177

views

Best practice for default parameters of methods of derived classes

I know that the following works on VC++12, so it's what I've been doing: class IBase { virtual void Method(int param = 0) = 0; // default here } class Derived { void Method(int param = 0); // default here } void Derived::Method(int param /*= 0*/) // no default here { // do something } Does the stand...
quant
1

votes
1

answer
47

views

How to SELECT INTO with a check on each row before insertion

I want to create a table using SELECT INTO but want to avoid creating rows where two of the columns are equal but in different order to two other columns. For example, say I have a query that generates the following data +----+----+ |col1|col2| +----+----+ |A |XYZ | +----+----+ |2 |4 | +----+-...
quant
1

votes
1

answer
397

views

How do I write a smart makefile?

I'm new to linux and new to makefiles so I'm a little stumped at this point. I've been staring the make manual for an hour now and figured I would just ask: I want to create a makefile for a relatively small project, whose source files are in proj/src/, and within subdirectories of that location. I...
quant

View additional