calculating how many lines of code in ipython notebook - ipython

just for curiosity sake - is there a way to find how many lines of code you've written in your ipython notebook? I have multiple lines per box, so I can't just count the number of boxes I have...

Related

jupyter notebook with octave: code cell is plain text by default

I use jupyter notebook with octave kernel and it runs quite fine.
After a while I wondered why highlighting looks so strange.
Then I realized that part of the notebook is detected as python although an octave kernel is running.
Part of the code cells, in fact most are plain text.
Now I found out in the bottom left corner, one can choose.
The language for octave is in fact MATLAB.
This improves appearance very much.
But now I wonder whether I really must switch each cell individually.
I also found autodetect but this never finds MATLAB.

FastText window size

I'm currently working on fastText unsuperived learning. I wanted clarify something of context window present in fastText documentation.
In the description of the fasttext library for python https://github.com/facebookresearch/fastText/tree/master/python for training a fastText model there are different arguments, one of the arguments is,
ws: size of the context window
My input file contains lines with 2 - 3 tokens.
Eg.,
Senior Database Administrator
Senior DotNet programmer
Network administrator
Head Programmer (Mainframe)
The default window size 5. Here, in the above example, I have lines with token count less than the window size. What will happen if the window size is bigger than the document length?
FastText (& related algorithms like word2vec) will simply use as much of the context window as is possible.
For example, assume a window-size of 5 and the input tokens:
['Senior', 'Database', 'Administrator']
When training with the 'center' word 'Senior', the algorithm would be ready to consult up-to-5 words in either direction.
But, there are 0 words preceding 'Senior', and only 2 words succeeding 'Senior', so only those 2 following words will be considered as neighbors.
(No 'plug values' will be used as if they were blank-neighbors, nor will any 'bleed-through' to beighboring texts occur.)
Two other related notes to keep in mind:
These algorithms do need neighboring words for any training to occur, so any texts with just a single word are essentially no-ops. (If there happens to be a word that only ever appears alone, you might still see a vector for it at the end of training, but in the implementations with which I am familiar, that will just be a randomly-initialized starting vector, completely untrained by real usage examples.)
Most implementations will simulate a weighting-of-neighboring-words by not *always using exactly your declared window-size, but rather, for each pass over a specific target center word, choosing a random window-size, from 1 to your chosen window-size. In this way, immediate-neighbors are always part of training, while words further away are more-often skipped.

Run Matlab commands with reduced priority

I frequently encounter the following problem: I start a time-consuming (sometimes parallelized) script, and while the said script is running Matlab becomes very slow & unresponsive. (I would like to keep editing files). I suspect that part of the problem is that the script that's running is eating up all CPU capacities.
Hence my question: is there a way to start all commands from within Matlab with a reduced process priority, while not reducing the priority of the Matlab GUI from which these processes are started? I'd be interested in solutions for Windows & Linux.
E.g., on Linux I know I can increase the niceness of the sub-processes using renice on the command line, but I obviously do not want to do so manually each time. I also checked whether there's a way to start the parallel worker threads with a modified priority, but I could not find anything in the documentation. Ideally - as in many other IDEs - there would be a setting somewhere in Matlab where one can configure how to run commands, and I would change it from matlab ... to nice -10 matlab ....

Anaconda Spyder integrated IPython display for dataframes

The new anaconda spyder has an integrated iPython console. I really dislike the way dataframes are displayed in this console. There are some border graphics around the dataframe and resizing that occurs with window resizing that make it difficult to examine the contents. In addition, often for large dataframes if one just types the variable name, we can only see a XX rows x YY columns display, not a display of the top corner of the dataframe.
How can I reset the dataframe display so that it displays the way a standard iPython (or iPython QT) console would display a dataframe, i.e. with no graphics?
Thanks.
The development version of Spyder has a Pandas Dataframe editor (and an numpy array editor, up to 3d). You can run this from source or wait for the next release, 2.3.1.
This is probably more adequate to edit or visualize dataframe than using the embedded qtconsole.

Is there a way to import the results or data from Matlab to Mathematica automatically?

Is there a way to import the results or data (such as matrices) from Matlab to Mathematica automatically? Or is there any way to run a Matlab program first and then run a Mathematica program automatically?
Thanks for any helpful answers!
There are at least three approaches to tackling this:
'Through' Java, using Mathematica's JLink and Matlab's own Java capabilities.
Either program can be run from the command line, execute a script and return output as required. Both programs can run 'external' commands and capture the results. Look, for example, in the Mathematica documentation under the heading External Programs. Matlab has similar capabilities.
If you are running on Linux, or a similar OS, you can pipe the output from one program into the other.
The difficulties of these approaches vary.
I stumbled upon this problem and after some tries I managed to create a simple algorithm that worked for me.
Save your matrix in Matlab using:
save('m','-v7','a')
m is the file, -v7 is the version( someone said it would worked better, I don't know) and a is the matrix. I didn't try with more than one matrix at a time.
Then in mathematica I used:
SetDirectory["Desktop"]
a = Import["m.mat"] ;
a=Partition[Flatten[a], 5000]
I set my directory to the location of my m.mat file and imported it.
In my case the matrix was 5000*5000 so I had to divided in parts with 5000 elements each.
If you have a N*K matrix try to divide by N and K to see what suits your needs.