What is meant by 'a[::]'? - list

I don't know the meaning of symbol '::'?
`
if a[::]==a[::-1]:
while a[::]==a[::-1] and len(a)!=0:
.

Related

How to show the + symbol in an equation that is generated by https://render.githubusercontent.com for github-pages?

I can't seem to get the "+" symbol to appear:
<img src="https://render.githubusercontent.com/render/math?math={\color{black} \large \sigma = f(\mu) = a\mu^2 + b\mu + c} "> Eqn(2)
It is giving me this wrong result. The appearance I desire is this correct appearance.
Quoting a comment by #Jishan in this answer
Anyone using this method, because + is an escape character in URI, use %2B to render +.

How to change commutativity of a SymPy symbol after creation?

Suppose I create a SymPy symbol x.
import sympy as sp
x = sp.Symbol('x', commutative = False)
How can I change the commutative assumption to True without creating a new Symbol?
I tried
with sp.assuming( sp.Q.commutative(x) ):
print( sp.ask( Q.commutative(x) ) )
But it still gives False.
SymPy objects are immutable, so this isn't possible. Furthermore commutative is not supported by the new assumptions system (ask, Q, assuming).
What you should do instead is create a new symbol and use subs to replace it in whatever expression you want to make it commutative in.

CC-mode assignment indenting in Emacs

I am writing a C++ program with Emacs CC-mode, When I write an expression that needs to wrap, how can I make the newline on the right side of the equal sign like this:
// Aligned
abc = longlonglong + longlonglong +
longlonglong;
// The actual situation
abc = longlonglong + longlonglong +
longlonglong;
With StackOverflow's hints, I tried several ways to customize the statement-cont variable, but only one method worked -- added the following code in ~/.emacs:
(c-add-style "Stroustrup"
'((c-basic-offset . 4)
(c-offsets-alist
(statement-cont . c-lineup-assignments))))
I found google-c-style.el's settings as follows:
(c-offsets-alist . ((arglist-intro google-c-lineup-expression-plus-4)
...
(statement-cont
.
(,(when (fboundp 'c-no-indent-after-java-annotations)
'c-no-indent-after-java-annotations)
,(when (fboundp 'c-lineup-assignments)
'c-lineup-assignments)
++))
...
(innamespace . 0))))
Who can tell me what this code means?
Because I only want to apply c-lineup-assignments to equations, I updated my settings reference to google-style code:
(c-add-style "Stroustrup"
'((c-basic-offset . 4)
(c-offsets-alist
(statement-cont . (when (looking-at "=")
'c-lineup-assignments
'+)))))
But when I run cc-mode the Emacs says Invalid indentation setting for symbol statement-cont: ...., so if I want only to apply the c-lineup-assignments to equations, how can I change this code ?
You're looking for c-lineup-assignments from cc-align. With your cursor on the continuation line, when you can type C-c C-o (or c-set-offset in case that key is modified) it should autofill with c-statement-cont. Hit return and set its value to c-lineup-assignments.

Sympy absolute value and arguments of complex symbols

In doing symbolic math with Sympy I encountered the following problem:
from sympy import *
txx, tyx, txy, tyy, tp, tn = symbols('t_xx t_yx t_xy t_yy t_p t_n', complex=True)
#define a complex symbol
tp = txx-I*tyx
Abs(tp), arg(tp)
#will just return |txx-i*tyx|, arg(txx-i*tyx)
However, the absolute value and argument returned is not in the form of sqrt(txx**2+tyx**2), atan(tyx/txx) as you would expect for complex numbers.
I also tried
simplify(Abs(tp).expand(complex=True))
#returns |Retxx-i*Retyx+i*Imtxx+Imtxy|, but no further simplification
which worked again for complex numbers but not the symbol of complex symbol defined here. Is this not implemented yet or am I not doing it right?
If you define your symbol list with the attribute real=True, then you will get the correct expression for Abs(tp). With your sympy symbols given as complex, then Abs() does not know the real and imaginary parts of these pieces txx, tyx, etc so the output of Abs() can not give you what you expected.

Mallet in R regex error :java.lang.NoSuchMethodException: No suitable method for the given parameters

Ive been following the tutorial on how to use mallet in R to create topic models. My text file has 1 sentence per line. It looks like this and has about 50 sentences.
Thank you again and have a good day :).
This is an apple.
This is awesome!
LOL!
i need 2.
.
.
.
This is my code:
Sys.setenv(NOAWT=TRUE)
#setup the workspace
# Set working directory
dir<-"/Users/jxn"
Dir <- "~/Desktop/Chat/malletR/text" # adjust to suit
require(mallet)
documents1 <- mallet.read.dir(Dir)
View(documents1)
stoplist1<-mallet.read.dir("~/Desktop/Chat/malletR/stoplists")
View(stoplist1)
**mallet.instances <- mallet.import(documents1$id, documents1$text, "~/Desktop/Chat/malletR/stoplists/en.txt", token.regexp ="\\p{L}[\\p{L}\\p{P}]+\\p{L}")**
Everything works except for the last line of the code
**`**mallet.instances <- mallet.import(documents1$id, documents1$text, "~/Desktop/Chat/malletR/stoplists/en.txt", token.regexp ="\\p{L}[\\p{L}\\p{P}]+\\p{L}")**`**
I keep getting this error :
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
java.lang.NoSuchMethodException: No suitable method for the given parameters
According to the package, this is how the function should be:
mallet.instances <- mallet.import(documents$id, documents$text, "en.txt",
token.regexp = "\\p{L}[\\p{L}\\p{P}]+\\p{L}")
I believe it has something to do with the token.regexp argument as
documents1 <- mallet.read.dir(Dir) works just fine which means that the first 3 arguments supplied to mallet.instances was correct.
This is a link to the git repo that i was following the tutorial from.
https://github.com/shawngraham/R/blob/master/topicmodel.R
Any help would be much appreciated.
Thanks,
J
I suspect the problem is with your text file. I have encountered the same error and resolved it by using the as.character() function as follows:
mallet.instances <- mallet.import(as.character(documents$id),
as.character(documents$text),
"en.txt",
FALSE,
token.regexp="\\p{L}[\\p{L}\\p{P}]+\\p{L}")
Are you sure you converted the id field also to character ? It is easy to overlook the advice and leave it as an integer.
Also there is a typo in the code sample: the backslashes have to be escaped:
token.regexp = "\\p{L}[\\p{L}\\p{P}]+\\p{L}"
This usually occurs because the html text editor eats up one backslash.