How to insert a literal tab instead of auto-completing in Jupyter? - ipython

It is easy to indent a whole line.
Just highlight the whole line and press Tab
Go to the start of the line and press Tab
Click anywhere in the line and press Ctrl + ]
Now the problem is how to insert indent in the middle of the line.
And also, how to indent at the end of the line.
Example usage scenario:
# Hyperparameters
LENGTH = 10 # length of foo
TEMP = 20 # temperature of bar
IV = 99.99 # induction variability of foo bar
Concretely, we want:
# Hyperparameters
LENGTH = 10 # length of foo
TEMP = 20 # temperature of bar
IV = 99.99 # induction variability of foo bar
Or even better (in some cases):
# Hyperparameters
LENGTH = 10 # length of foo
TEMP = 20 # temperature of bar
IV = 99.99 # induction variability of foo bar
Note that by pressing the Tab button however, we are actually calling auto-complete instead of indenting.
Of course we can always manual align them by using spacebar, but then we will have to do this every time we tune the hyperparameters.
So, how to indent instead of auto-completing in Jupyter?
P.S. Yes, I am aware of print("\t"), copying the output and pasting the indent. But that is not desirable.

One alternative would be to use the Alt keyboard sequence.
In this case it would be Alt + 09. It is about as short as one could hope for.
For this to work you need a numpad on your keyboard, as the top row of numbers on the keyboard does not work to produce Alt keyboard sequences.
However, this does leave rather ugly arrows in place of the tab, which seems to be the way Jupyter Notebooks displays tab characters.

Related

How to fix extra space that MATLAB displays after first iteration

I have an fprintf statement which loops 3 times in order to display some data. After the first iteration, MATLAB displays a mysterious space even though I have not added an extra \t. It acts as if I had an if statement to display a different fprintf statement after the first iteration, but I have nothing like that on the code. See picture on the link for the result it displays
% Display results
fprintf('Panel\tPressure Cl\tCd\t| Panel\tPressure Cl\tCd\n')
for q = 1:length(AOA)
fprintf('--------------\t-------\t------- |--------------\t--
-----\t-------\n')
fprintf('AOA %.0f°\t\t%.4f\t%.4f\t|AOA %.0f°
\t\t%.4f\t%.4f\n'...
,AOA(q),Cl(q),CD(q),AOA(q),ClFinal(q),CDFinal(q))
fprintf('--------------\t-------\t------- |--------------\t--
-----\t-------\n')
for j = 1:length(pressure{1})
fprintf('%.0f\t%.4f\t |\t |\t|%.0f\t%.4f\n',j+1,pressure{q}
(j),j+1,pFinal{q}(j))
end
end
When you fprintf a \t character, there is an automatic space padding up to 4 spaces. If the string has less than 4 characters, the string will be placed at the start and be "space padded" until 4 characters have been filled (in reality, the space padded characters resemble just one character). If the string has more than 4 characters, then it will space pad at 8, 12, 16, etc...
Here is what your question is really about:
fprintf('Panel\tPressure Cl\tCd\t| Panel\tPressure Cl\tCd\n')
The first string Panel has 5 characters, and therefore will be space padded with the equivalent of 3 spaces at the end of the first Panel. However, the second string | Panel has 7 characters, and therefore will only need the equivalent of 1 space at the end of the second string.
To remove your spacing issue, and have a more uniform spacing between your text headers, you can place a tab character after every header you want, and change your formating for your other fprintf statements accordingly:
fprintf('Panel\tPressure\tCl\t\tCd\t\t|\tPanel\tPressure\tCl\t\tCd\n')
You can also view this link for another example of how space padding works.
Also, here is the MATLAB Documentation on Formatting Text.

How to dig a multi-line matrix assignment from history?

A few days ago, I did a long assignment of data into a variable:
m = [ 0 0 0
1 0 3
2 6 9
...
59 2 5];
This was a 60x3 matrix of data, which I copy-pasted from somewhere, and I don't have the data anymore. So the only place I have these numbers is Matlab history.
Today, I want to do additional calculations on these numbers, so I want to load them into a variable again. However, when I press the up key, I can repeat the following previous command:
m = [ 0 0 0
This is not enough. How can I get the whole multi-line assignment from history?
Go to your command history and press ctrl+F and enter your search phrase. Make sure to select the option to search from the beginning of the command instead of anywhere.
Then, you can click on the bracket to the left of the search results to select the whole command at once.

Ti Basic (Ti-82 Plus) - Replace variable by numbers and X's

I whant to replace a variable by some numbers and X's or even a direct equation like 3X+2 = 5
Yeah I'm codding a resolution of equations :D (i'm borred)
This is what i've written right now
Prompt E
Prompt F
while T [not equal to] 1
X+0.01 -> X
If E=F
1 -> T
If E=F
Disp X
End
So what i'm trying to do is say E is 3X+2 and F is 5
I test all the possible solutions by replacing X by every number and when it equals to F (so 5) i stop and print X
It works when I replace directly in the code the E and F but it's long and useless if I whant to use it.
If 3X+2=5
1 -> T
If 3X+2=5
Disp X
End
This works !!
So is it possible for the calculator to interpret that i'm saying that E is a long sentence ?
Thanks so much !
Ps : Don't worry if i make mistakes in my orthograph, (i'm french)
Ps 2 : Don't just tell me how to do a resolution of equation (Don't tell me what I can't do !! (lost (4 8 15 16 23 42)))
Are you asking how to input "3X+2" into the variable E?
In this case, you wouldn't want to use a variable, because variables in TI-84 can only be numbers. You would use strings, which store text instead of numbers. Go to VARS > String... to see the list of strings available.
Now, to find the numerical value of strings, you would use the expr( command. For example, expr("3X+2") where X=1 would return 5. You can find the expr( command in the catalog (2ND + 0).
You're looking for equation variables.
An expression can be stored into an equation variable such as Y₁; it will be evaluated every time it is encountered.
"3X+2→Y₁
5→X
Disp Y₁
-2→X
Disp Y₁
The above will print
17
-4
Equation variables are easier to use than strings, because they are automatically evaluated. There's no need to use expr(. To find the equation variables, press VARS > ENTER.

TI-BASIC tab character / output formatting

I've written a program on my TI-nspire CAS calculator that outputs something similar to the following...
intercepts
x = 2 and x = 4
y = 0
derivative
2x - 4
turning points
(2, -4)
This is obviously a fair bit of information to output over multiple lines in a calculator.
I was wondering how I might go about outputting this a little better, say, placing the x and y intercepts on the same line seperated by a tab, or having the turning points printed on the same line (if more than one were printed. They're currently kept in a list and iterated through, Disp 'ing each).
Does TI-Basic have a TAB character, or is there a method that allows things to be printed on the same line (through multiple statements. Like Disp but without a trailing newline suffix).
There is no TAB character in TI-BASIC.
I would suggest using spaces and determining the length of the first line if you want the spacing to be consistent.

How can I convert hexadecimal to decimal numbers in calc of Emacs?

How can I convert hexadecimal to decimal numbers in Emacs calc?
For example, if I enter FF, I want it to convert it to 255.
UPDATE: How do I get the reverse operation, turn base 10 to base 16?
You can enter any number in the format <base>#<number>. Example: 16#FF is immediately converted to 255.
For the reverse, you need to set the output display mode. In this example, d r 16 RET sets the display to base 16. Set it to base 10 to get the default behaviour again.
By the way, you can also Read The Fine ManualTM: GNU Emacs Calc Manual.
Svante answered your question, but I'd like to add that the Radix Display Mode change has a quicker keystroke:
Show in hexidecimal mode: d 6
Show in decimal mode: d 0
Of course you could type 16#FF to enter 0xFF, but there is a more convenient way.
The other option:
change the display radix to hex with d 6
then enter all the hex numbers you want by prefixing them with a # like #FF and <enter>. (The # means interpret number with given display radix)
After this, change the display radix back to decimal with d 0.
Note: A number entered without # always inserts a decimal number.
Note2: This also works the other way round.
Negative Values:
Now lets say you have a 8-bit system and you want to know how decimal -3 is stored in this systems RAM.
switch word size: b w 8
enter dec -3 by typing 3 n and <enter>
set display radix to hex with two's complement notation: O d 6. (The O as Option is important to enable two's complement.)
Note: you see 16##FD. Two # means it is signed and the value stored in RAM is 0xFD
The above stuff works also with d 2, d 8 (as shortcuts for bin and oct) and other possible display radixes from 2 to 36 (d r <radix-number>).
This info is taken from the Emacs Calc Manual.