澳门在线威尼斯官方 > 电脑操作 > LaTex in 马克down

原标题:LaTex in 马克down

浏览次数:52 时间:2019-11-17

 

Lambda 是匿名函数

一些链接: Lambda Functions, Lambda Tutorial, and Python Functions.

# Example function
def addS(x):
    return x + 's'
#lambda 形式
addSLambda = lambda x: x + 's'

# 乘法
multiplyByTen = lambda x: x * 10
print multiplyByTen(5)

#lambda fewer steps than def 
# The first function should add two values, while the second function should subtract the second  value from the first value.
def plus(x, y):
    return x + y

def minus(x, y):
    return x - y

functions = [plus, minus]
print functions[0](4, 5)
print functions[1](4, 5)

# lambda
lambdaFunctions = [lambda x,y : x+y ,  lambda x,y: x-y]
print lambdaFunctions[0](4, 5)
print lambdaFunctions[1](4, 5)

Lambda expressions consist of a single expression statement and cannot contain other simple statements. In short, this means that the lambda expression needs to evaluate to a value and exist on a single logical line. If more complex logic is necessary, use def in place of lambda.
Expression statements evaluate to a value (sometimes that value is None). Lambda expressions automatically return the value of their expression statement. In fact, a return statement in a lambda would raise a SyntaxError.
The following Python keywords refer to simple statements that cannot be used in a lambda expression: assert, pass, del, print, return, yield, raise, break, continue, import, global, and exec. Also, note that assignment statements (=) and augmented assignment statements (e.g. +=) cannot be used either.

1.样式系列¶

Python 基础

3.3.希腊字母表¶

字母 公式 字母 公式 字母 公式
$alpha$ $alpha$ $beta$ $beta$ $chi$ $chi$
$delta$ $delta$ $Delta$ $Delta$ $epsilon$ $epsilon$
$eta$ $eta$ $Gamma$ $Gamma$ $iota$ $iota$
$kappa$ $kappa$ $lambda$ $lambda$ $Lambda$ $Lambda$
$mu$ $mu$ $nabla$ $nabla$ $nu$ $nu$
$omega$ $omega$ $Omega$ $Omega$ $phi$ $phi$
$Phi$ $Phi$ $pi$ $pi$ $Pi$ $Pi$
$psi$ $psi$ $Psi$ $Psi$ $rho$ $rho$
$sigma$ $sigma$ $Sigma$ $Sigma$ $tau$ $tau$
$theta$ $theta$ $Theta$ $Theta$ $upsilon$ $upsilon$
$varepsilon$ $varepsilon$ $varsigma$ $varsigma$ $vartheta$ $vartheta$
$xi$ $xi$ $zeta$ $zeta$

The element-wise calculation is as follows:

$$ mathbf{x} odot mathbf{y} = begin{bmatrix} x_1 y_1 \ x_2 y_2 \ vdots \ x_n y_n end{bmatrix} $$

2.1.常用表达式¶

常用数学 LaTex公式
$sqrt{ab}$ $sqrt{ab}$
$sqrt[n]{ab}$ $sqrt[n]{ab}$
$log_{a}{b}$ $log_{a}{b}$
$lg{ab}$ $lg{ab}$
$a^{b}$ $a^{b}$
$a_{b}$ $a_{b}$
$x_a^b$ $x_a^b$
$int$ $int$
$int_{a}^{b}$ $int_{a}^{b}$
$oint$ $oint$
$oint_a^b$ $oint_a^b$
$sum$ $sum$
$sum_a^b$ $sum_a^b$
$coprod$ $coprod$
$coprod_a^b$ $coprod_a^b$
$prod$ $prod$
$prod_a^b$ $prod_a^b$
$bigcap$ $bigcap$
$bigcap_a^b$ $bigcap_a^b$
$bigcup$ $bigcup$
$bigcup_a^b$ $bigcup_a^b$
$bigsqcup$ $bigsqcup$
$bigsqcup_a^b$ $bigsqcup_a^b$
$bigvee$ $bigvee$
$bigvee_a^b$ $bigvee_a^b$
$bigwedge$ $bigwedge$
$bigwedge_a^b$ $bigwedge_a^b$
$widetilde{ab}$ $widetilde{ab}$
$widehat{ab}$ $widehat{ab}$
$overleftarrow{ab}$ $overleftarrow{ab}$
$overrightarrow{ab}$ $overrightarrow{ab}$
$overbrace{ab}$ $overbrace{ab}$
$underbrace{ab}$ $underbrace{ab}$
$underline{ab}$ $underline{ab}$
$overline{ab}$ $overline{ab}$
$frac{ab}{cd}$ $frac{ab}{cd}$
$frac{partial a}{partial b}$ $frac{partial a}{partial b}$
$frac{text{d}x}{text{d}y}$ $frac{text{d}x}{text{d}y}$
$lim_{a rightarrow b}$ $lim_{a rightarrow b}$

 

Note that DenseVector stores all values as np.float64

DenseVector objects exist locally and are not inherently distributed. DenseVector objects can be used in the distributed setting by either passing functions that contain them to resilient distributed dataset (RDD) transformations or by distributing them directly as RDDs.

from pyspark.mllib.linalg import DenseVector

numpyVector = np.array([-3, -4, 5])
print 'nnumpyVector:n{0}'.format(numpyVector)

# Create a DenseVector consisting of the values [3.0, 4.0, 5.0]
myDenseVector = DenseVector([3,4,5])
# Calculate the dot product between the two vectors.
denseDotProduct = DenseVector.dot(myDenseVector,numpyVector)

print 'myDenseVector:n{0}'.format(myDenseVector)
print 'ndenseDotProduct:n{0}'.format(denseDotProduct)

numpyVector:
[-3 -4 5]
myDenseVector:
[3.0,4.0,5.0]
denseDotProduct:
0.0


2.2.附录:数学公式大全¶

数学公式 LaTex公式
$displaystylesumlimits_{i=0}^n i^3$ $displaystylesumlimits_{i=0}^n i^3$
$left(begin{array}{c}a\ bend{array}right)$ $left(begin{array}{c}a\ bend{array}right)$
$left(frac{a^2}{b^3}right)$ $left(frac{a^2}{b^3}right)$
$left.frac{a^3}{3}rightlvert_0^1$ $left.frac{a^3}{3}rightlvert_0^1$
$begin{bmatrix}a & b \c & d end{bmatrix}$ $begin{bmatrix}a & b \c & d end{bmatrix}$
$begin{cases}a & x = 0\b & x > 0end{cases}$ $begin{cases}a & x = 0\b & x > 0end{cases}$
$sqrt{frac{n}{n-1} S}$ $sqrt{frac{n}{n-1} S}$
$begin{pmatrix} alpha& beta^{*}\ gamma^{*}& delta end{pmatrix}$ $begin{pmatrix} alpha& beta^{*}\ gamma^{*}& delta end{pmatrix}$
$A:xleftarrow{n+mu-1}:B$ $A:xleftarrow{n+mu-1}:B$
$B:xrightarrow[T]{npm i-1}:C$ $B:xrightarrow[T]{npm i-1}:C$
$frac{1}{k}log_2 c(f);$ $frac{1}{k}log_2 c(f);$
$iintlimits_A f(x,y);$ $iintlimits_A f(x,y);$
$x^n + y^n = z^n$ $x^n + y^n = z^n$
$E=mc^2$ $E=mc^2$
$e^{pi i} - 1 = 0$ $e^{pi i} - 1 = 0$
$p(x) = 3x^6$ $p(x) = 3x^6$
$3x + y = 12$ $3x + y = 12$
$int_0^infty mathrm{e}^{-x},mathrm{d}x$ $int_0^infty mathrm{e}^{-x},mathrm{d}x$
$sqrt[n]{1+x+x^2+ldots}$ $sqrt[n]{1+x+x^2+ldots}$
$binom{x}{y} = frac{x!}{y!(x-y)!}$ $binom{x}{y} = frac{x!}{y!(x-y)!}$
$frac{frac{1}{x}+frac{1}{y}}{y-z}$ $frac{frac{1}{x}+frac{1}{y}}{y-z}$
$f(x)=frac{P(x)}{Q(x)}$ $f(x)=frac{P(x)}{Q(x)}$
$frac{1+frac{a}{b}}{1+frac{1}{1+frac{1}{a}}}$ $frac{1+frac{a}{b}}{1+frac{1}{1+frac{1}{a}}}$
$sum_{substack{0le ile m\ 0lt jlt n}} P(i,j)$ $sum_{substack{0le ile m\ 0lt jlt n}} P(i,j)$
$lim_{x to infty} exp(-x) = 0$ $lim_{x to infty} exp(-x) = 0$
$cos (2theta) = cos^2 theta - sin^2 theta$ $cos (2theta) = cos^2 theta - sin^2 theta$

 

PySpark provides a DenseVector class within the module pyspark.mllib.linalg.

DenseVector is used to store arrays of values for use in PySpark. DenseVector actually stores values in a NumPy array and delegates calculations to that object. You can create a new DenseVector using DenseVector() and passing in an NumPy array or a Python list.

4.2.矩阵系列¶

$$
begin{bmatrix}
1&0&0 \
0&1&0 \
0&0&1
end{bmatrix}
$$

$$ begin{bmatrix} 1&0&0 \ 0&1&0 \ 0&0&1 end{bmatrix} $$


(1b) 点乘 Element-wise multiplication and dot product

1.4.大小¶

$tiny 萌萌哒$

$scriptsize 萌萌哒$

$small 萌萌哒$

$normalsize 萌萌哒(正常)$

$large 萌萌哒$

$Large 萌萌哒$

$huge 萌萌哒$

$Huge 萌萌哒$

$tiny 萌萌哒$

$scriptsize 萌萌哒$

$small 萌萌哒$

$normalsize 萌萌哒(正常)$

$large 萌萌哒$

$Large 萌萌哒$

$huge 萌萌哒$

$Huge 萌萌哒$

如果是单行写,记得加换行符号:

$tiny 萌萌哒\$
$scriptsize 萌萌哒\$
$small 萌萌哒\$
$normalsize 萌萌哒(正常)\$
$large 萌萌哒\$
$Large 萌萌哒\$
$huge 萌萌哒\$
$Huge 萌萌哒\$

(1c) 矩阵计算 Matrix math

3.2.常用符号¶

基本符号 公式 基本符号 公式 基本符号 公式
$cdot$ $cdot$ $vdots$ $vdots$ $grave{x}$ $grave{x}$
$.$ $.$ $ddots$ $ddots$ $breve{x}$ $breve{x}$
$*$ $*$ $,$ $,$ $dot{x}$ $dot{x}$
$+$ $+$ $!$ $!$ $widehat{xxx}$ $widehat{xxx}$
$-$ $-$ $;$ $;$ $ddot{x}$ $ddot{x}$
$times$ $times$ $?$ $?$ $check{x}$ $check{x}$
$div$ $div$ $colon$ $colon$ $ddot{x}$ $ddot{x}$
$=$ $=$ $acute{x}$ $acute{x}$ $tilde{x}$ $tilde{x}$
$neq$ $neq$ $bar{x}$ $bar{x}$ $hat{x}$ $hat{x}$
$dotsm$ $dotsm$ $vec{x}$ $vec{x}$ $dddot{x}$ $dddot{x}$
$dotso$ $dotso$ $widetilde{xxx}$ $widetilde{xxx}$ $backslash$ $backslash$
$/$ $/$ $bracevert$ $bracevert$ $]$ $]$
$smallsetminus$ $smallsetminus$ $lVert$ $lVert$ $lbrace$ $lbrace$
$arrowvert$ $arrowvert$ $rVert$ $rVert$ $rbrace$ $rbrace$
$lvert$ $lvert$ $lgroup$ $lgroup$ $langle$ $langle$
$lvert$ $lvert$ $rgroup$ $rgroup$ $rangle$ $rangle$
$rvert$ $rvert$ $[$ $[$ $lmoustache$ $lmoustache$
$rmoustache$ $rmoustache$ $lceil$ $lceil$ $rceil$ $rceil$
$lfloor$ $lfloor$ $rfloor$ $rfloor$

(1a) 标量相乘 Scalar multiplication

$ a $ is the scalar (constant) and $ mathbf{v} $ is the vector
$$ a mathbf{v} = begin{bmatrix} a v_1 \ a v_2 \ vdots \ a v_n end{bmatrix} $$

# Create a numpy array with the values 1, 2, 3
simpleArray = np.array([1,2,3])
# Perform the scalar product of 5 and the numpy array
timesFive = simpleArray * 5
print simpleArray
print timesFive
-----
#result
[1 2 3]
[5 10 15

3.数学符号¶

np.matrix() 生成矩阵

上次写了Markdown,这次用到了LaTex,也出一期(吐槽,工作量比Markdown高太多...)

Part 2: Additional NumPy and Spark linear algebra

Markdown基础:

matrix math on NumPy matrices using *

在线预览:http://github.lesschina.com/python/ai/math/LaTex in Markdown.html

For this exercise, multiply $ mathbf{A} $ times its transpose $ ( mathbf{A}^top ) $ and then calculate the inverse of the result $ ( [ mathbf{A} mathbf{A}^top ]^{-1} ) $.

from numpy.linalg import inv

A = np.matrix([[1,2,3,4],[5,6,7,8]])
print 'A:n{0}'.format(A)
# Print A transpose
print 'nA transpose:n{0}'.format(A.T)

# Multiply A by A transpose
AAt = A * A.T
print 'nAAt:n{0}'.format(AAt)

# Invert AAt with np.linalg.inv()
AAtInv = np.linalg.inv(AAt)
print 'nAAtInv:n{0}'.format(AAtInv)

# Show inverse times matrix equals identity
# We round due to numerical precision
print 'nAAtInv * AAt:n{0}'.format((AAtInv * AAt).round(4))
print 'nAAtInv * AAt:n{0}'.format((AAtInv * AAt).round(4))

result

A:
[[1 2 3 4]
[5 6 7 8]]

A transpose:
[[1 5]
[2 6]
[3 7]
[4 8]]

AAt:
[[ 30 70]
[ 70 174]]

AAtInv:
[[ 0.54375 -0.21875]
[-0.21875 0.09375]]

AAtInv * AAt:
[[ 1. 0.]
[-0. 1.]]

AAtInv * AAt:
[[ 1. 0.]
[-0. 1.]]


本文由澳门在线威尼斯官方发布于电脑操作,转载请注明出处:LaTex in 马克down

关键词:

上一篇:没有了

下一篇:没有了