_add_newdocs.py 359 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639
  1. # Docstrings for generated ufuncs
  2. #
  3. # The syntax is designed to look like the function add_newdoc is being
  4. # called from numpy.lib, but in this file add_newdoc puts the
  5. # docstrings in a dictionary. This dictionary is used in
  6. # _generate_pyx.py to generate the docstrings for the ufuncs in
  7. # scipy.special at the C level when the ufuncs are created at compile
  8. # time.
  9. from typing import Dict
  10. docdict: Dict[str, str] = {}
  11. def get(name):
  12. return docdict.get(name)
  13. def add_newdoc(name, doc):
  14. docdict[name] = doc
  15. add_newdoc("_sf_error_test_function",
  16. """
  17. Private function; do not use.
  18. """)
  19. add_newdoc("_cosine_cdf",
  20. """
  21. _cosine_cdf(x)
  22. Cumulative distribution function (CDF) of the cosine distribution::
  23. { 0, x < -pi
  24. cdf(x) = { (pi + x + sin(x))/(2*pi), -pi <= x <= pi
  25. { 1, x > pi
  26. Parameters
  27. ----------
  28. x : array_like
  29. `x` must contain real numbers.
  30. Returns
  31. -------
  32. scalar or ndarray
  33. The cosine distribution CDF evaluated at `x`.
  34. """)
  35. add_newdoc("_cosine_invcdf",
  36. """
  37. _cosine_invcdf(p)
  38. Inverse of the cumulative distribution function (CDF) of the cosine
  39. distribution.
  40. The CDF of the cosine distribution is::
  41. cdf(x) = (pi + x + sin(x))/(2*pi)
  42. This function computes the inverse of cdf(x).
  43. Parameters
  44. ----------
  45. p : array_like
  46. `p` must contain real numbers in the interval ``0 <= p <= 1``.
  47. `nan` is returned for values of `p` outside the interval [0, 1].
  48. Returns
  49. -------
  50. scalar or ndarray
  51. The inverse of the cosine distribution CDF evaluated at `p`.
  52. """)
  53. add_newdoc("sph_harm",
  54. r"""
  55. sph_harm(m, n, theta, phi, out=None)
  56. Compute spherical harmonics.
  57. The spherical harmonics are defined as
  58. .. math::
  59. Y^m_n(\theta,\phi) = \sqrt{\frac{2n+1}{4\pi} \frac{(n-m)!}{(n+m)!}}
  60. e^{i m \theta} P^m_n(\cos(\phi))
  61. where :math:`P_n^m` are the associated Legendre functions; see `lpmv`.
  62. Parameters
  63. ----------
  64. m : array_like
  65. Order of the harmonic (int); must have ``|m| <= n``.
  66. n : array_like
  67. Degree of the harmonic (int); must have ``n >= 0``. This is
  68. often denoted by ``l`` (lower case L) in descriptions of
  69. spherical harmonics.
  70. theta : array_like
  71. Azimuthal (longitudinal) coordinate; must be in ``[0, 2*pi]``.
  72. phi : array_like
  73. Polar (colatitudinal) coordinate; must be in ``[0, pi]``.
  74. out : ndarray, optional
  75. Optional output array for the function values
  76. Returns
  77. -------
  78. y_mn : complex scalar or ndarray
  79. The harmonic :math:`Y^m_n` sampled at ``theta`` and ``phi``.
  80. Notes
  81. -----
  82. There are different conventions for the meanings of the input
  83. arguments ``theta`` and ``phi``. In SciPy ``theta`` is the
  84. azimuthal angle and ``phi`` is the polar angle. It is common to
  85. see the opposite convention, that is, ``theta`` as the polar angle
  86. and ``phi`` as the azimuthal angle.
  87. Note that SciPy's spherical harmonics include the Condon-Shortley
  88. phase [2]_ because it is part of `lpmv`.
  89. With SciPy's conventions, the first several spherical harmonics
  90. are
  91. .. math::
  92. Y_0^0(\theta, \phi) &= \frac{1}{2} \sqrt{\frac{1}{\pi}} \\
  93. Y_1^{-1}(\theta, \phi) &= \frac{1}{2} \sqrt{\frac{3}{2\pi}}
  94. e^{-i\theta} \sin(\phi) \\
  95. Y_1^0(\theta, \phi) &= \frac{1}{2} \sqrt{\frac{3}{\pi}}
  96. \cos(\phi) \\
  97. Y_1^1(\theta, \phi) &= -\frac{1}{2} \sqrt{\frac{3}{2\pi}}
  98. e^{i\theta} \sin(\phi).
  99. References
  100. ----------
  101. .. [1] Digital Library of Mathematical Functions, 14.30.
  102. https://dlmf.nist.gov/14.30
  103. .. [2] https://en.wikipedia.org/wiki/Spherical_harmonics#Condon.E2.80.93Shortley_phase
  104. """)
  105. add_newdoc("_ellip_harm",
  106. """
  107. Internal function, use `ellip_harm` instead.
  108. """)
  109. add_newdoc("_ellip_norm",
  110. """
  111. Internal function, use `ellip_norm` instead.
  112. """)
  113. add_newdoc("_lambertw",
  114. """
  115. Internal function, use `lambertw` instead.
  116. """)
  117. add_newdoc("voigt_profile",
  118. r"""
  119. voigt_profile(x, sigma, gamma, out=None)
  120. Voigt profile.
  121. The Voigt profile is a convolution of a 1-D Normal distribution with
  122. standard deviation ``sigma`` and a 1-D Cauchy distribution with half-width at
  123. half-maximum ``gamma``.
  124. If ``sigma = 0``, PDF of Cauchy distribution is returned.
  125. Conversely, if ``gamma = 0``, PDF of Normal distribution is returned.
  126. If ``sigma = gamma = 0``, the return value is ``Inf`` for ``x = 0``, and ``0`` for all other ``x``.
  127. Parameters
  128. ----------
  129. x : array_like
  130. Real argument
  131. sigma : array_like
  132. The standard deviation of the Normal distribution part
  133. gamma : array_like
  134. The half-width at half-maximum of the Cauchy distribution part
  135. out : ndarray, optional
  136. Optional output array for the function values
  137. Returns
  138. -------
  139. scalar or ndarray
  140. The Voigt profile at the given arguments
  141. Notes
  142. -----
  143. It can be expressed in terms of Faddeeva function
  144. .. math:: V(x; \sigma, \gamma) = \frac{Re[w(z)]}{\sigma\sqrt{2\pi}},
  145. .. math:: z = \frac{x + i\gamma}{\sqrt{2}\sigma}
  146. where :math:`w(z)` is the Faddeeva function.
  147. See Also
  148. --------
  149. wofz : Faddeeva function
  150. References
  151. ----------
  152. .. [1] https://en.wikipedia.org/wiki/Voigt_profile
  153. Examples
  154. --------
  155. Calculate the function at point 2 for ``sigma=1`` and ``gamma=1``.
  156. >>> from scipy.special import voigt_profile
  157. >>> import numpy as np
  158. >>> import matplotlib.pyplot as plt
  159. >>> voigt_profile(2, 1., 1.)
  160. 0.09071519942627544
  161. Calculate the function at several points by providing a NumPy array
  162. for `x`.
  163. >>> values = np.array([-2., 0., 5])
  164. >>> voigt_profile(values, 1., 1.)
  165. array([0.0907152 , 0.20870928, 0.01388492])
  166. Plot the function for different parameter sets.
  167. >>> fig, ax = plt.subplots(figsize=(8, 8))
  168. >>> x = np.linspace(-10, 10, 500)
  169. >>> parameters_list = [(1.5, 0., "solid"), (1.3, 0.5, "dashed"),
  170. ... (0., 1.8, "dotted"), (1., 1., "dashdot")]
  171. >>> for params in parameters_list:
  172. ... sigma, gamma, linestyle = params
  173. ... voigt = voigt_profile(x, sigma, gamma)
  174. ... ax.plot(x, voigt, label=rf"$\sigma={sigma},\, \gamma={gamma}$",
  175. ... ls=linestyle)
  176. >>> ax.legend()
  177. >>> plt.show()
  178. Verify visually that the Voigt profile indeed arises as the convolution
  179. of a normal and a Cauchy distribution.
  180. >>> from scipy.signal import convolve
  181. >>> x, dx = np.linspace(-10, 10, 500, retstep=True)
  182. >>> def gaussian(x, sigma):
  183. ... return np.exp(-0.5 * x**2/sigma**2)/(sigma * np.sqrt(2*np.pi))
  184. >>> def cauchy(x, gamma):
  185. ... return gamma/(np.pi * (np.square(x)+gamma**2))
  186. >>> sigma = 2
  187. >>> gamma = 1
  188. >>> gauss_profile = gaussian(x, sigma)
  189. >>> cauchy_profile = cauchy(x, gamma)
  190. >>> convolved = dx * convolve(cauchy_profile, gauss_profile, mode="same")
  191. >>> voigt = voigt_profile(x, sigma, gamma)
  192. >>> fig, ax = plt.subplots(figsize=(8, 8))
  193. >>> ax.plot(x, gauss_profile, label="Gauss: $G$", c='b')
  194. >>> ax.plot(x, cauchy_profile, label="Cauchy: $C$", c='y', ls="dashed")
  195. >>> xx = 0.5*(x[1:] + x[:-1]) # midpoints
  196. >>> ax.plot(xx, convolved[1:], label="Convolution: $G * C$", ls='dashdot',
  197. ... c='k')
  198. >>> ax.plot(x, voigt, label="Voigt", ls='dotted', c='r')
  199. >>> ax.legend()
  200. >>> plt.show()
  201. """)
  202. add_newdoc("wrightomega",
  203. r"""
  204. wrightomega(z, out=None)
  205. Wright Omega function.
  206. Defined as the solution to
  207. .. math::
  208. \omega + \log(\omega) = z
  209. where :math:`\log` is the principal branch of the complex logarithm.
  210. Parameters
  211. ----------
  212. z : array_like
  213. Points at which to evaluate the Wright Omega function
  214. out : ndarray, optional
  215. Optional output array for the function values
  216. Returns
  217. -------
  218. omega : scalar or ndarray
  219. Values of the Wright Omega function
  220. Notes
  221. -----
  222. .. versionadded:: 0.19.0
  223. The function can also be defined as
  224. .. math::
  225. \omega(z) = W_{K(z)}(e^z)
  226. where :math:`K(z) = \lceil (\Im(z) - \pi)/(2\pi) \rceil` is the
  227. unwinding number and :math:`W` is the Lambert W function.
  228. The implementation here is taken from [1]_.
  229. See Also
  230. --------
  231. lambertw : The Lambert W function
  232. References
  233. ----------
  234. .. [1] Lawrence, Corless, and Jeffrey, "Algorithm 917: Complex
  235. Double-Precision Evaluation of the Wright :math:`\omega`
  236. Function." ACM Transactions on Mathematical Software,
  237. 2012. :doi:`10.1145/2168773.2168779`.
  238. Examples
  239. --------
  240. >>> import numpy as np
  241. >>> from scipy.special import wrightomega, lambertw
  242. >>> wrightomega([-2, -1, 0, 1, 2])
  243. array([0.12002824, 0.27846454, 0.56714329, 1. , 1.5571456 ])
  244. Complex input:
  245. >>> wrightomega(3 + 5j)
  246. (1.5804428632097158+3.8213626783287937j)
  247. Verify that ``wrightomega(z)`` satisfies ``w + log(w) = z``:
  248. >>> w = -5 + 4j
  249. >>> wrightomega(w + np.log(w))
  250. (-5+4j)
  251. Verify the connection to ``lambertw``:
  252. >>> z = 0.5 + 3j
  253. >>> wrightomega(z)
  254. (0.0966015889280649+1.4937828458191993j)
  255. >>> lambertw(np.exp(z))
  256. (0.09660158892806493+1.4937828458191993j)
  257. >>> z = 0.5 + 4j
  258. >>> wrightomega(z)
  259. (-0.3362123489037213+2.282986001579032j)
  260. >>> lambertw(np.exp(z), k=1)
  261. (-0.33621234890372115+2.282986001579032j)
  262. """)
  263. add_newdoc("agm",
  264. """
  265. agm(a, b, out=None)
  266. Compute the arithmetic-geometric mean of `a` and `b`.
  267. Start with a_0 = a and b_0 = b and iteratively compute::
  268. a_{n+1} = (a_n + b_n)/2
  269. b_{n+1} = sqrt(a_n*b_n)
  270. a_n and b_n converge to the same limit as n increases; their common
  271. limit is agm(a, b).
  272. Parameters
  273. ----------
  274. a, b : array_like
  275. Real values only. If the values are both negative, the result
  276. is negative. If one value is negative and the other is positive,
  277. `nan` is returned.
  278. out : ndarray, optional
  279. Optional output array for the function values
  280. Returns
  281. -------
  282. scalar or ndarray
  283. The arithmetic-geometric mean of `a` and `b`.
  284. Examples
  285. --------
  286. >>> import numpy as np
  287. >>> from scipy.special import agm
  288. >>> a, b = 24.0, 6.0
  289. >>> agm(a, b)
  290. 13.458171481725614
  291. Compare that result to the iteration:
  292. >>> while a != b:
  293. ... a, b = (a + b)/2, np.sqrt(a*b)
  294. ... print("a = %19.16f b=%19.16f" % (a, b))
  295. ...
  296. a = 15.0000000000000000 b=12.0000000000000000
  297. a = 13.5000000000000000 b=13.4164078649987388
  298. a = 13.4582039324993694 b=13.4581390309909850
  299. a = 13.4581714817451772 b=13.4581714817060547
  300. a = 13.4581714817256159 b=13.4581714817256159
  301. When array-like arguments are given, broadcasting applies:
  302. >>> a = np.array([[1.5], [3], [6]]) # a has shape (3, 1).
  303. >>> b = np.array([6, 12, 24, 48]) # b has shape (4,).
  304. >>> agm(a, b)
  305. array([[ 3.36454287, 5.42363427, 9.05798751, 15.53650756],
  306. [ 4.37037309, 6.72908574, 10.84726853, 18.11597502],
  307. [ 6. , 8.74074619, 13.45817148, 21.69453707]])
  308. """)
  309. add_newdoc("airy",
  310. r"""
  311. airy(z, out=None)
  312. Airy functions and their derivatives.
  313. Parameters
  314. ----------
  315. z : array_like
  316. Real or complex argument.
  317. out : tuple of ndarray, optional
  318. Optional output arrays for the function values
  319. Returns
  320. -------
  321. Ai, Aip, Bi, Bip : 4-tuple of scalar or ndarray
  322. Airy functions Ai and Bi, and their derivatives Aip and Bip.
  323. Notes
  324. -----
  325. The Airy functions Ai and Bi are two independent solutions of
  326. .. math:: y''(x) = x y(x).
  327. For real `z` in [-10, 10], the computation is carried out by calling
  328. the Cephes [1]_ `airy` routine, which uses power series summation
  329. for small `z` and rational minimax approximations for large `z`.
  330. Outside this range, the AMOS [2]_ `zairy` and `zbiry` routines are
  331. employed. They are computed using power series for :math:`|z| < 1` and
  332. the following relations to modified Bessel functions for larger `z`
  333. (where :math:`t \equiv 2 z^{3/2}/3`):
  334. .. math::
  335. Ai(z) = \frac{1}{\pi \sqrt{3}} K_{1/3}(t)
  336. Ai'(z) = -\frac{z}{\pi \sqrt{3}} K_{2/3}(t)
  337. Bi(z) = \sqrt{\frac{z}{3}} \left(I_{-1/3}(t) + I_{1/3}(t) \right)
  338. Bi'(z) = \frac{z}{\sqrt{3}} \left(I_{-2/3}(t) + I_{2/3}(t)\right)
  339. See also
  340. --------
  341. airye : exponentially scaled Airy functions.
  342. References
  343. ----------
  344. .. [1] Cephes Mathematical Functions Library,
  345. http://www.netlib.org/cephes/
  346. .. [2] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  347. of a Complex Argument and Nonnegative Order",
  348. http://netlib.org/amos/
  349. Examples
  350. --------
  351. Compute the Airy functions on the interval [-15, 5].
  352. >>> import numpy as np
  353. >>> from scipy import special
  354. >>> x = np.linspace(-15, 5, 201)
  355. >>> ai, aip, bi, bip = special.airy(x)
  356. Plot Ai(x) and Bi(x).
  357. >>> import matplotlib.pyplot as plt
  358. >>> plt.plot(x, ai, 'r', label='Ai(x)')
  359. >>> plt.plot(x, bi, 'b--', label='Bi(x)')
  360. >>> plt.ylim(-0.5, 1.0)
  361. >>> plt.grid()
  362. >>> plt.legend(loc='upper left')
  363. >>> plt.show()
  364. """)
  365. add_newdoc("airye",
  366. """
  367. airye(z, out=None)
  368. Exponentially scaled Airy functions and their derivatives.
  369. Scaling::
  370. eAi = Ai * exp(2.0/3.0*z*sqrt(z))
  371. eAip = Aip * exp(2.0/3.0*z*sqrt(z))
  372. eBi = Bi * exp(-abs(2.0/3.0*(z*sqrt(z)).real))
  373. eBip = Bip * exp(-abs(2.0/3.0*(z*sqrt(z)).real))
  374. Parameters
  375. ----------
  376. z : array_like
  377. Real or complex argument.
  378. out : tuple of ndarray, optional
  379. Optional output arrays for the function values
  380. Returns
  381. -------
  382. eAi, eAip, eBi, eBip : 4-tuple of scalar or ndarray
  383. Exponentially scaled Airy functions eAi and eBi, and their derivatives
  384. eAip and eBip
  385. Notes
  386. -----
  387. Wrapper for the AMOS [1]_ routines `zairy` and `zbiry`.
  388. See also
  389. --------
  390. airy
  391. References
  392. ----------
  393. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  394. of a Complex Argument and Nonnegative Order",
  395. http://netlib.org/amos/
  396. Examples
  397. --------
  398. We can compute exponentially scaled Airy functions and their derivatives:
  399. >>> import numpy as np
  400. >>> from scipy.special import airye
  401. >>> import matplotlib.pyplot as plt
  402. >>> z = np.linspace(0, 50, 500)
  403. >>> eAi, eAip, eBi, eBip = airye(z)
  404. >>> f, ax = plt.subplots(2, 1, sharex=True)
  405. >>> for ind, data in enumerate([[eAi, eAip, ["eAi", "eAip"]],
  406. ... [eBi, eBip, ["eBi", "eBip"]]]):
  407. ... ax[ind].plot(z, data[0], "-r", z, data[1], "-b")
  408. ... ax[ind].legend(data[2])
  409. ... ax[ind].grid(True)
  410. >>> plt.show()
  411. We can compute these using usual non-scaled Airy functions by:
  412. >>> from scipy.special import airy
  413. >>> Ai, Aip, Bi, Bip = airy(z)
  414. >>> np.allclose(eAi, Ai * np.exp(2.0 / 3.0 * z * np.sqrt(z)))
  415. True
  416. >>> np.allclose(eAip, Aip * np.exp(2.0 / 3.0 * z * np.sqrt(z)))
  417. True
  418. >>> np.allclose(eBi, Bi * np.exp(-abs(np.real(2.0 / 3.0 * z * np.sqrt(z)))))
  419. True
  420. >>> np.allclose(eBip, Bip * np.exp(-abs(np.real(2.0 / 3.0 * z * np.sqrt(z)))))
  421. True
  422. Comparing non-scaled and exponentially scaled ones, the usual non-scaled
  423. function quickly underflows for large values, whereas the exponentially
  424. scaled function does not.
  425. >>> airy(200)
  426. (0.0, 0.0, nan, nan)
  427. >>> airye(200)
  428. (0.07501041684381093, -1.0609012305109042, 0.15003188417418148, 2.1215836725571093)
  429. """)
  430. add_newdoc("bdtr",
  431. r"""
  432. bdtr(k, n, p, out=None)
  433. Binomial distribution cumulative distribution function.
  434. Sum of the terms 0 through `floor(k)` of the Binomial probability density.
  435. .. math::
  436. \mathrm{bdtr}(k, n, p) = \sum_{j=0}^{\lfloor k \rfloor} {{n}\choose{j}} p^j (1-p)^{n-j}
  437. Parameters
  438. ----------
  439. k : array_like
  440. Number of successes (double), rounded down to the nearest integer.
  441. n : array_like
  442. Number of events (int).
  443. p : array_like
  444. Probability of success in a single event (float).
  445. out : ndarray, optional
  446. Optional output array for the function values
  447. Returns
  448. -------
  449. y : scalar or ndarray
  450. Probability of `floor(k)` or fewer successes in `n` independent events with
  451. success probabilities of `p`.
  452. Notes
  453. -----
  454. The terms are not summed directly; instead the regularized incomplete beta
  455. function is employed, according to the formula,
  456. .. math::
  457. \mathrm{bdtr}(k, n, p) = I_{1 - p}(n - \lfloor k \rfloor, \lfloor k \rfloor + 1).
  458. Wrapper for the Cephes [1]_ routine `bdtr`.
  459. References
  460. ----------
  461. .. [1] Cephes Mathematical Functions Library,
  462. http://www.netlib.org/cephes/
  463. """)
  464. add_newdoc("bdtrc",
  465. r"""
  466. bdtrc(k, n, p, out=None)
  467. Binomial distribution survival function.
  468. Sum of the terms `floor(k) + 1` through `n` of the binomial probability
  469. density,
  470. .. math::
  471. \mathrm{bdtrc}(k, n, p) = \sum_{j=\lfloor k \rfloor +1}^n {{n}\choose{j}} p^j (1-p)^{n-j}
  472. Parameters
  473. ----------
  474. k : array_like
  475. Number of successes (double), rounded down to nearest integer.
  476. n : array_like
  477. Number of events (int)
  478. p : array_like
  479. Probability of success in a single event.
  480. out : ndarray, optional
  481. Optional output array for the function values
  482. Returns
  483. -------
  484. y : scalar or ndarray
  485. Probability of `floor(k) + 1` or more successes in `n` independent
  486. events with success probabilities of `p`.
  487. See also
  488. --------
  489. bdtr
  490. betainc
  491. Notes
  492. -----
  493. The terms are not summed directly; instead the regularized incomplete beta
  494. function is employed, according to the formula,
  495. .. math::
  496. \mathrm{bdtrc}(k, n, p) = I_{p}(\lfloor k \rfloor + 1, n - \lfloor k \rfloor).
  497. Wrapper for the Cephes [1]_ routine `bdtrc`.
  498. References
  499. ----------
  500. .. [1] Cephes Mathematical Functions Library,
  501. http://www.netlib.org/cephes/
  502. """)
  503. add_newdoc("bdtri",
  504. r"""
  505. bdtri(k, n, y, out=None)
  506. Inverse function to `bdtr` with respect to `p`.
  507. Finds the event probability `p` such that the sum of the terms 0 through
  508. `k` of the binomial probability density is equal to the given cumulative
  509. probability `y`.
  510. Parameters
  511. ----------
  512. k : array_like
  513. Number of successes (float), rounded down to the nearest integer.
  514. n : array_like
  515. Number of events (float)
  516. y : array_like
  517. Cumulative probability (probability of `k` or fewer successes in `n`
  518. events).
  519. out : ndarray, optional
  520. Optional output array for the function values
  521. Returns
  522. -------
  523. p : scalar or ndarray
  524. The event probability such that `bdtr(\lfloor k \rfloor, n, p) = y`.
  525. See also
  526. --------
  527. bdtr
  528. betaincinv
  529. Notes
  530. -----
  531. The computation is carried out using the inverse beta integral function
  532. and the relation,::
  533. 1 - p = betaincinv(n - k, k + 1, y).
  534. Wrapper for the Cephes [1]_ routine `bdtri`.
  535. References
  536. ----------
  537. .. [1] Cephes Mathematical Functions Library,
  538. http://www.netlib.org/cephes/
  539. """)
  540. add_newdoc("bdtrik",
  541. """
  542. bdtrik(y, n, p, out=None)
  543. Inverse function to `bdtr` with respect to `k`.
  544. Finds the number of successes `k` such that the sum of the terms 0 through
  545. `k` of the Binomial probability density for `n` events with probability
  546. `p` is equal to the given cumulative probability `y`.
  547. Parameters
  548. ----------
  549. y : array_like
  550. Cumulative probability (probability of `k` or fewer successes in `n`
  551. events).
  552. n : array_like
  553. Number of events (float).
  554. p : array_like
  555. Success probability (float).
  556. out : ndarray, optional
  557. Optional output array for the function values
  558. Returns
  559. -------
  560. k : scalar or ndarray
  561. The number of successes `k` such that `bdtr(k, n, p) = y`.
  562. See also
  563. --------
  564. bdtr
  565. Notes
  566. -----
  567. Formula 26.5.24 of [1]_ is used to reduce the binomial distribution to the
  568. cumulative incomplete beta distribution.
  569. Computation of `k` involves a search for a value that produces the desired
  570. value of `y`. The search relies on the monotonicity of `y` with `k`.
  571. Wrapper for the CDFLIB [2]_ Fortran routine `cdfbin`.
  572. References
  573. ----------
  574. .. [1] Milton Abramowitz and Irene A. Stegun, eds.
  575. Handbook of Mathematical Functions with Formulas,
  576. Graphs, and Mathematical Tables. New York: Dover, 1972.
  577. .. [2] Barry Brown, James Lovato, and Kathy Russell,
  578. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  579. Functions, Inverses, and Other Parameters.
  580. """)
  581. add_newdoc("bdtrin",
  582. """
  583. bdtrin(k, y, p, out=None)
  584. Inverse function to `bdtr` with respect to `n`.
  585. Finds the number of events `n` such that the sum of the terms 0 through
  586. `k` of the Binomial probability density for events with probability `p` is
  587. equal to the given cumulative probability `y`.
  588. Parameters
  589. ----------
  590. k : array_like
  591. Number of successes (float).
  592. y : array_like
  593. Cumulative probability (probability of `k` or fewer successes in `n`
  594. events).
  595. p : array_like
  596. Success probability (float).
  597. out : ndarray, optional
  598. Optional output array for the function values
  599. Returns
  600. -------
  601. n : scalar or ndarray
  602. The number of events `n` such that `bdtr(k, n, p) = y`.
  603. See also
  604. --------
  605. bdtr
  606. Notes
  607. -----
  608. Formula 26.5.24 of [1]_ is used to reduce the binomial distribution to the
  609. cumulative incomplete beta distribution.
  610. Computation of `n` involves a search for a value that produces the desired
  611. value of `y`. The search relies on the monotonicity of `y` with `n`.
  612. Wrapper for the CDFLIB [2]_ Fortran routine `cdfbin`.
  613. References
  614. ----------
  615. .. [1] Milton Abramowitz and Irene A. Stegun, eds.
  616. Handbook of Mathematical Functions with Formulas,
  617. Graphs, and Mathematical Tables. New York: Dover, 1972.
  618. .. [2] Barry Brown, James Lovato, and Kathy Russell,
  619. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  620. Functions, Inverses, and Other Parameters.
  621. """)
  622. add_newdoc(
  623. "binom",
  624. r"""
  625. binom(x, y, out=None)
  626. Binomial coefficient considered as a function of two real variables.
  627. For real arguments, the binomial coefficient is defined as
  628. .. math::
  629. \binom{x}{y} = \frac{\Gamma(x + 1)}{\Gamma(y + 1)\Gamma(x - y + 1)} =
  630. \frac{1}{(x + 1)\mathrm{B}(x - y + 1, y + 1)}
  631. Where :math:`\Gamma` is the Gamma function (`gamma`) and :math:`\mathrm{B}`
  632. is the Beta function (`beta`) [1]_.
  633. Parameters
  634. ----------
  635. x, y: array_like
  636. Real arguments to :math:`\binom{x}{y}`.
  637. out : ndarray, optional
  638. Optional output array for the function values
  639. Returns
  640. -------
  641. scalar or ndarray
  642. Value of binomial coefficient.
  643. See Also
  644. --------
  645. comb : The number of combinations of N things taken k at a time.
  646. Notes
  647. -----
  648. The Gamma function has poles at non-positive integers and tends to either
  649. positive or negative infinity depending on the direction on the real line
  650. from which a pole is approached. When considered as a function of two real
  651. variables, :math:`\binom{x}{y}` is thus undefined when `x` is a negative
  652. integer. `binom` returns ``nan`` when ``x`` is a negative integer. This
  653. is the case even when ``x`` is a negative integer and ``y`` an integer,
  654. contrary to the usual convention for defining :math:`\binom{n}{k}` when it
  655. is considered as a function of two integer variables.
  656. References
  657. ----------
  658. .. [1] https://en.wikipedia.org/wiki/Binomial_coefficient
  659. Examples
  660. --------
  661. The following examples illustrate the ways in which `binom` differs from
  662. the function `comb`.
  663. >>> from scipy.special import binom, comb
  664. When ``exact=False`` and ``x`` and ``y`` are both positive, `comb` calls
  665. `binom` internally.
  666. >>> x, y = 3, 2
  667. >>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
  668. (3.0, 3.0, 3)
  669. For larger values, `comb` with ``exact=True`` no longer agrees
  670. with `binom`.
  671. >>> x, y = 43, 23
  672. >>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
  673. (960566918219.9999, 960566918219.9999, 960566918220)
  674. `binom` returns ``nan`` when ``x`` is a negative integer, but is otherwise
  675. defined for negative arguments. `comb` returns 0 whenever one of ``x`` or
  676. ``y`` is negative or ``x`` is less than ``y``.
  677. >>> x, y = -3, 2
  678. >>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
  679. (nan, 0.0, 0)
  680. >>> x, y = -3.1, 2.2
  681. >>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
  682. (18.714147876804432, 0.0, 0)
  683. >>> x, y = 2.2, 3.1
  684. >>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
  685. (0.037399983365134115, 0.0, 0)
  686. """
  687. )
  688. add_newdoc("btdtria",
  689. r"""
  690. btdtria(p, b, x, out=None)
  691. Inverse of `btdtr` with respect to `a`.
  692. This is the inverse of the beta cumulative distribution function, `btdtr`,
  693. considered as a function of `a`, returning the value of `a` for which
  694. `btdtr(a, b, x) = p`, or
  695. .. math::
  696. p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1}\,dt
  697. Parameters
  698. ----------
  699. p : array_like
  700. Cumulative probability, in [0, 1].
  701. b : array_like
  702. Shape parameter (`b` > 0).
  703. x : array_like
  704. The quantile, in [0, 1].
  705. out : ndarray, optional
  706. Optional output array for the function values
  707. Returns
  708. -------
  709. a : scalar or ndarray
  710. The value of the shape parameter `a` such that `btdtr(a, b, x) = p`.
  711. See Also
  712. --------
  713. btdtr : Cumulative distribution function of the beta distribution.
  714. btdtri : Inverse with respect to `x`.
  715. btdtrib : Inverse with respect to `b`.
  716. Notes
  717. -----
  718. Wrapper for the CDFLIB [1]_ Fortran routine `cdfbet`.
  719. The cumulative distribution function `p` is computed using a routine by
  720. DiDinato and Morris [2]_. Computation of `a` involves a search for a value
  721. that produces the desired value of `p`. The search relies on the
  722. monotonicity of `p` with `a`.
  723. References
  724. ----------
  725. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  726. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  727. Functions, Inverses, and Other Parameters.
  728. .. [2] DiDinato, A. R. and Morris, A. H.,
  729. Algorithm 708: Significant Digit Computation of the Incomplete Beta
  730. Function Ratios. ACM Trans. Math. Softw. 18 (1993), 360-373.
  731. """)
  732. add_newdoc("btdtrib",
  733. r"""
  734. btdtria(a, p, x, out=None)
  735. Inverse of `btdtr` with respect to `b`.
  736. This is the inverse of the beta cumulative distribution function, `btdtr`,
  737. considered as a function of `b`, returning the value of `b` for which
  738. `btdtr(a, b, x) = p`, or
  739. .. math::
  740. p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1}\,dt
  741. Parameters
  742. ----------
  743. a : array_like
  744. Shape parameter (`a` > 0).
  745. p : array_like
  746. Cumulative probability, in [0, 1].
  747. x : array_like
  748. The quantile, in [0, 1].
  749. out : ndarray, optional
  750. Optional output array for the function values
  751. Returns
  752. -------
  753. b : scalar or ndarray
  754. The value of the shape parameter `b` such that `btdtr(a, b, x) = p`.
  755. See Also
  756. --------
  757. btdtr : Cumulative distribution function of the beta distribution.
  758. btdtri : Inverse with respect to `x`.
  759. btdtria : Inverse with respect to `a`.
  760. Notes
  761. -----
  762. Wrapper for the CDFLIB [1]_ Fortran routine `cdfbet`.
  763. The cumulative distribution function `p` is computed using a routine by
  764. DiDinato and Morris [2]_. Computation of `b` involves a search for a value
  765. that produces the desired value of `p`. The search relies on the
  766. monotonicity of `p` with `b`.
  767. References
  768. ----------
  769. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  770. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  771. Functions, Inverses, and Other Parameters.
  772. .. [2] DiDinato, A. R. and Morris, A. H.,
  773. Algorithm 708: Significant Digit Computation of the Incomplete Beta
  774. Function Ratios. ACM Trans. Math. Softw. 18 (1993), 360-373.
  775. """)
  776. add_newdoc("bei",
  777. r"""
  778. bei(x, out=None)
  779. Kelvin function bei.
  780. Defined as
  781. .. math::
  782. \mathrm{bei}(x) = \Im[J_0(x e^{3 \pi i / 4})]
  783. where :math:`J_0` is the Bessel function of the first kind of
  784. order zero (see `jv`). See [dlmf]_ for more details.
  785. Parameters
  786. ----------
  787. x : array_like
  788. Real argument.
  789. out : ndarray, optional
  790. Optional output array for the function results.
  791. Returns
  792. -------
  793. scalar or ndarray
  794. Values of the Kelvin function.
  795. See Also
  796. --------
  797. ber : the corresponding real part
  798. beip : the derivative of bei
  799. jv : Bessel function of the first kind
  800. References
  801. ----------
  802. .. [dlmf] NIST, Digital Library of Mathematical Functions,
  803. https://dlmf.nist.gov/10.61
  804. Examples
  805. --------
  806. It can be expressed using Bessel functions.
  807. >>> import numpy as np
  808. >>> import scipy.special as sc
  809. >>> x = np.array([1.0, 2.0, 3.0, 4.0])
  810. >>> sc.jv(0, x * np.exp(3 * np.pi * 1j / 4)).imag
  811. array([0.24956604, 0.97229163, 1.93758679, 2.29269032])
  812. >>> sc.bei(x)
  813. array([0.24956604, 0.97229163, 1.93758679, 2.29269032])
  814. """)
  815. add_newdoc("beip",
  816. r"""
  817. beip(x, out=None)
  818. Derivative of the Kelvin function bei.
  819. Parameters
  820. ----------
  821. x : array_like
  822. Real argument.
  823. out : ndarray, optional
  824. Optional output array for the function results.
  825. Returns
  826. -------
  827. scalar or ndarray
  828. The values of the derivative of bei.
  829. See Also
  830. --------
  831. bei
  832. References
  833. ----------
  834. .. [dlmf] NIST, Digital Library of Mathematical Functions,
  835. https://dlmf.nist.gov/10#PT5
  836. """)
  837. add_newdoc("ber",
  838. r"""
  839. ber(x, out=None)
  840. Kelvin function ber.
  841. Defined as
  842. .. math::
  843. \mathrm{ber}(x) = \Re[J_0(x e^{3 \pi i / 4})]
  844. where :math:`J_0` is the Bessel function of the first kind of
  845. order zero (see `jv`). See [dlmf]_ for more details.
  846. Parameters
  847. ----------
  848. x : array_like
  849. Real argument.
  850. out : ndarray, optional
  851. Optional output array for the function results.
  852. Returns
  853. -------
  854. scalar or ndarray
  855. Values of the Kelvin function.
  856. See Also
  857. --------
  858. bei : the corresponding real part
  859. berp : the derivative of bei
  860. jv : Bessel function of the first kind
  861. References
  862. ----------
  863. .. [dlmf] NIST, Digital Library of Mathematical Functions,
  864. https://dlmf.nist.gov/10.61
  865. Examples
  866. --------
  867. It can be expressed using Bessel functions.
  868. >>> import numpy as np
  869. >>> import scipy.special as sc
  870. >>> x = np.array([1.0, 2.0, 3.0, 4.0])
  871. >>> sc.jv(0, x * np.exp(3 * np.pi * 1j / 4)).real
  872. array([ 0.98438178, 0.75173418, -0.22138025, -2.56341656])
  873. >>> sc.ber(x)
  874. array([ 0.98438178, 0.75173418, -0.22138025, -2.56341656])
  875. """)
  876. add_newdoc("berp",
  877. r"""
  878. berp(x, out=None)
  879. Derivative of the Kelvin function ber.
  880. Parameters
  881. ----------
  882. x : array_like
  883. Real argument.
  884. out : ndarray, optional
  885. Optional output array for the function results.
  886. Returns
  887. -------
  888. scalar or ndarray
  889. The values of the derivative of ber.
  890. See Also
  891. --------
  892. ber
  893. References
  894. ----------
  895. .. [dlmf] NIST, Digital Library of Mathematical Functions,
  896. https://dlmf.nist.gov/10#PT5
  897. """)
  898. add_newdoc("besselpoly",
  899. r"""
  900. besselpoly(a, lmb, nu, out=None)
  901. Weighted integral of the Bessel function of the first kind.
  902. Computes
  903. .. math::
  904. \int_0^1 x^\lambda J_\nu(2 a x) \, dx
  905. where :math:`J_\nu` is a Bessel function and :math:`\lambda=lmb`,
  906. :math:`\nu=nu`.
  907. Parameters
  908. ----------
  909. a : array_like
  910. Scale factor inside the Bessel function.
  911. lmb : array_like
  912. Power of `x`
  913. nu : array_like
  914. Order of the Bessel function.
  915. out : ndarray, optional
  916. Optional output array for the function results.
  917. Returns
  918. -------
  919. scalar or ndarray
  920. Value of the integral.
  921. References
  922. ----------
  923. .. [1] Cephes Mathematical Functions Library,
  924. http://www.netlib.org/cephes/
  925. Examples
  926. --------
  927. Evaluate the function for one parameter set.
  928. >>> from scipy.special import besselpoly
  929. >>> besselpoly(1, 1, 1)
  930. 0.24449718372863877
  931. Evaluate the function for different scale factors.
  932. >>> import numpy as np
  933. >>> factors = np.array([0., 3., 6.])
  934. >>> besselpoly(factors, 1, 1)
  935. array([ 0. , -0.00549029, 0.00140174])
  936. Plot the function for varying powers, orders and scales.
  937. >>> import matplotlib.pyplot as plt
  938. >>> fig, ax = plt.subplots()
  939. >>> powers = np.linspace(0, 10, 100)
  940. >>> orders = [1, 2, 3]
  941. >>> scales = [1, 2]
  942. >>> all_combinations = [(order, scale) for order in orders
  943. ... for scale in scales]
  944. >>> for order, scale in all_combinations:
  945. ... ax.plot(powers, besselpoly(scale, powers, order),
  946. ... label=rf"$\nu={order}, a={scale}$")
  947. >>> ax.legend()
  948. >>> ax.set_xlabel(r"$\lambda$")
  949. >>> ax.set_ylabel(r"$\int_0^1 x^{\lambda} J_{\nu}(2ax)\,dx$")
  950. >>> plt.show()
  951. """)
  952. add_newdoc("beta",
  953. r"""
  954. beta(a, b, out=None)
  955. Beta function.
  956. This function is defined in [1]_ as
  957. .. math::
  958. B(a, b) = \int_0^1 t^{a-1}(1-t)^{b-1}dt
  959. = \frac{\Gamma(a)\Gamma(b)}{\Gamma(a+b)},
  960. where :math:`\Gamma` is the gamma function.
  961. Parameters
  962. ----------
  963. a, b : array_like
  964. Real-valued arguments
  965. out : ndarray, optional
  966. Optional output array for the function result
  967. Returns
  968. -------
  969. scalar or ndarray
  970. Value of the beta function
  971. See Also
  972. --------
  973. gamma : the gamma function
  974. betainc : the regularized incomplete beta function
  975. betaln : the natural logarithm of the absolute
  976. value of the beta function
  977. References
  978. ----------
  979. .. [1] NIST Digital Library of Mathematical Functions,
  980. Eq. 5.12.1. https://dlmf.nist.gov/5.12
  981. Examples
  982. --------
  983. >>> import scipy.special as sc
  984. The beta function relates to the gamma function by the
  985. definition given above:
  986. >>> sc.beta(2, 3)
  987. 0.08333333333333333
  988. >>> sc.gamma(2)*sc.gamma(3)/sc.gamma(2 + 3)
  989. 0.08333333333333333
  990. As this relationship demonstrates, the beta function
  991. is symmetric:
  992. >>> sc.beta(1.7, 2.4)
  993. 0.16567527689031739
  994. >>> sc.beta(2.4, 1.7)
  995. 0.16567527689031739
  996. This function satisfies :math:`B(1, b) = 1/b`:
  997. >>> sc.beta(1, 4)
  998. 0.25
  999. """)
  1000. add_newdoc("betainc",
  1001. r"""
  1002. betainc(a, b, x, out=None)
  1003. Regularized incomplete beta function.
  1004. Computes the regularized incomplete beta function, defined as [1]_:
  1005. .. math::
  1006. I_x(a, b) = \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)} \int_0^x
  1007. t^{a-1}(1-t)^{b-1}dt,
  1008. for :math:`0 \leq x \leq 1`.
  1009. Parameters
  1010. ----------
  1011. a, b : array_like
  1012. Positive, real-valued parameters
  1013. x : array_like
  1014. Real-valued such that :math:`0 \leq x \leq 1`,
  1015. the upper limit of integration
  1016. out : ndarray, optional
  1017. Optional output array for the function values
  1018. Returns
  1019. -------
  1020. scalar or ndarray
  1021. Value of the regularized incomplete beta function
  1022. See Also
  1023. --------
  1024. beta : beta function
  1025. betaincinv : inverse of the regularized incomplete beta function
  1026. Notes
  1027. -----
  1028. The term *regularized* in the name of this function refers to the
  1029. scaling of the function by the gamma function terms shown in the
  1030. formula. When not qualified as *regularized*, the name *incomplete
  1031. beta function* often refers to just the integral expression,
  1032. without the gamma terms. One can use the function `beta` from
  1033. `scipy.special` to get this "nonregularized" incomplete beta
  1034. function by multiplying the result of ``betainc(a, b, x)`` by
  1035. ``beta(a, b)``.
  1036. References
  1037. ----------
  1038. .. [1] NIST Digital Library of Mathematical Functions
  1039. https://dlmf.nist.gov/8.17
  1040. Examples
  1041. --------
  1042. Let :math:`B(a, b)` be the `beta` function.
  1043. >>> import scipy.special as sc
  1044. The coefficient in terms of `gamma` is equal to
  1045. :math:`1/B(a, b)`. Also, when :math:`x=1`
  1046. the integral is equal to :math:`B(a, b)`.
  1047. Therefore, :math:`I_{x=1}(a, b) = 1` for any :math:`a, b`.
  1048. >>> sc.betainc(0.2, 3.5, 1.0)
  1049. 1.0
  1050. It satisfies
  1051. :math:`I_x(a, b) = x^a F(a, 1-b, a+1, x)/ (aB(a, b))`,
  1052. where :math:`F` is the hypergeometric function `hyp2f1`:
  1053. >>> a, b, x = 1.4, 3.1, 0.5
  1054. >>> x**a * sc.hyp2f1(a, 1 - b, a + 1, x)/(a * sc.beta(a, b))
  1055. 0.8148904036225295
  1056. >>> sc.betainc(a, b, x)
  1057. 0.8148904036225296
  1058. This functions satisfies the relationship
  1059. :math:`I_x(a, b) = 1 - I_{1-x}(b, a)`:
  1060. >>> sc.betainc(2.2, 3.1, 0.4)
  1061. 0.49339638807619446
  1062. >>> 1 - sc.betainc(3.1, 2.2, 1 - 0.4)
  1063. 0.49339638807619446
  1064. """)
  1065. add_newdoc("betaincinv",
  1066. r"""
  1067. betaincinv(a, b, y, out=None)
  1068. Inverse of the regularized incomplete beta function.
  1069. Computes :math:`x` such that:
  1070. .. math::
  1071. y = I_x(a, b) = \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)}
  1072. \int_0^x t^{a-1}(1-t)^{b-1}dt,
  1073. where :math:`I_x` is the normalized incomplete beta
  1074. function `betainc` and
  1075. :math:`\Gamma` is the `gamma` function [1]_.
  1076. Parameters
  1077. ----------
  1078. a, b : array_like
  1079. Positive, real-valued parameters
  1080. y : array_like
  1081. Real-valued input
  1082. out : ndarray, optional
  1083. Optional output array for function values
  1084. Returns
  1085. -------
  1086. scalar or ndarray
  1087. Value of the inverse of the regularized incomplete beta function
  1088. See Also
  1089. --------
  1090. betainc : regularized incomplete beta function
  1091. gamma : gamma function
  1092. References
  1093. ----------
  1094. .. [1] NIST Digital Library of Mathematical Functions
  1095. https://dlmf.nist.gov/8.17
  1096. Examples
  1097. --------
  1098. >>> import scipy.special as sc
  1099. This function is the inverse of `betainc` for fixed
  1100. values of :math:`a` and :math:`b`.
  1101. >>> a, b = 1.2, 3.1
  1102. >>> y = sc.betainc(a, b, 0.2)
  1103. >>> sc.betaincinv(a, b, y)
  1104. 0.2
  1105. >>>
  1106. >>> a, b = 7.5, 0.4
  1107. >>> x = sc.betaincinv(a, b, 0.5)
  1108. >>> sc.betainc(a, b, x)
  1109. 0.5
  1110. """)
  1111. add_newdoc("betaln",
  1112. """
  1113. betaln(a, b, out=None)
  1114. Natural logarithm of absolute value of beta function.
  1115. Computes ``ln(abs(beta(a, b)))``.
  1116. Parameters
  1117. ----------
  1118. a, b : array_like
  1119. Positive, real-valued parameters
  1120. out : ndarray, optional
  1121. Optional output array for function values
  1122. Returns
  1123. -------
  1124. scalar or ndarray
  1125. Value of the betaln function
  1126. See Also
  1127. --------
  1128. gamma : the gamma function
  1129. betainc : the regularized incomplete beta function
  1130. beta : the beta function
  1131. Examples
  1132. --------
  1133. >>> import numpy as np
  1134. >>> from scipy.special import betaln, beta
  1135. Verify that, for moderate values of ``a`` and ``b``, ``betaln(a, b)``
  1136. is the same as ``log(beta(a, b))``:
  1137. >>> betaln(3, 4)
  1138. -4.0943445622221
  1139. >>> np.log(beta(3, 4))
  1140. -4.0943445622221
  1141. In the following ``beta(a, b)`` underflows to 0, so we can't compute
  1142. the logarithm of the actual value.
  1143. >>> a = 400
  1144. >>> b = 900
  1145. >>> beta(a, b)
  1146. 0.0
  1147. We can compute the logarithm of ``beta(a, b)`` by using `betaln`:
  1148. >>> betaln(a, b)
  1149. -804.3069951764146
  1150. """)
  1151. add_newdoc("boxcox",
  1152. """
  1153. boxcox(x, lmbda, out=None)
  1154. Compute the Box-Cox transformation.
  1155. The Box-Cox transformation is::
  1156. y = (x**lmbda - 1) / lmbda if lmbda != 0
  1157. log(x) if lmbda == 0
  1158. Returns `nan` if ``x < 0``.
  1159. Returns `-inf` if ``x == 0`` and ``lmbda < 0``.
  1160. Parameters
  1161. ----------
  1162. x : array_like
  1163. Data to be transformed.
  1164. lmbda : array_like
  1165. Power parameter of the Box-Cox transform.
  1166. out : ndarray, optional
  1167. Optional output array for the function values
  1168. Returns
  1169. -------
  1170. y : scalar or ndarray
  1171. Transformed data.
  1172. Notes
  1173. -----
  1174. .. versionadded:: 0.14.0
  1175. Examples
  1176. --------
  1177. >>> from scipy.special import boxcox
  1178. >>> boxcox([1, 4, 10], 2.5)
  1179. array([ 0. , 12.4 , 126.09110641])
  1180. >>> boxcox(2, [0, 1, 2])
  1181. array([ 0.69314718, 1. , 1.5 ])
  1182. """)
  1183. add_newdoc("boxcox1p",
  1184. """
  1185. boxcox1p(x, lmbda, out=None)
  1186. Compute the Box-Cox transformation of 1 + `x`.
  1187. The Box-Cox transformation computed by `boxcox1p` is::
  1188. y = ((1+x)**lmbda - 1) / lmbda if lmbda != 0
  1189. log(1+x) if lmbda == 0
  1190. Returns `nan` if ``x < -1``.
  1191. Returns `-inf` if ``x == -1`` and ``lmbda < 0``.
  1192. Parameters
  1193. ----------
  1194. x : array_like
  1195. Data to be transformed.
  1196. lmbda : array_like
  1197. Power parameter of the Box-Cox transform.
  1198. out : ndarray, optional
  1199. Optional output array for the function values
  1200. Returns
  1201. -------
  1202. y : scalar or ndarray
  1203. Transformed data.
  1204. Notes
  1205. -----
  1206. .. versionadded:: 0.14.0
  1207. Examples
  1208. --------
  1209. >>> from scipy.special import boxcox1p
  1210. >>> boxcox1p(1e-4, [0, 0.5, 1])
  1211. array([ 9.99950003e-05, 9.99975001e-05, 1.00000000e-04])
  1212. >>> boxcox1p([0.01, 0.1], 0.25)
  1213. array([ 0.00996272, 0.09645476])
  1214. """)
  1215. add_newdoc("inv_boxcox",
  1216. """
  1217. inv_boxcox(y, lmbda, out=None)
  1218. Compute the inverse of the Box-Cox transformation.
  1219. Find ``x`` such that::
  1220. y = (x**lmbda - 1) / lmbda if lmbda != 0
  1221. log(x) if lmbda == 0
  1222. Parameters
  1223. ----------
  1224. y : array_like
  1225. Data to be transformed.
  1226. lmbda : array_like
  1227. Power parameter of the Box-Cox transform.
  1228. out : ndarray, optional
  1229. Optional output array for the function values
  1230. Returns
  1231. -------
  1232. x : scalar or ndarray
  1233. Transformed data.
  1234. Notes
  1235. -----
  1236. .. versionadded:: 0.16.0
  1237. Examples
  1238. --------
  1239. >>> from scipy.special import boxcox, inv_boxcox
  1240. >>> y = boxcox([1, 4, 10], 2.5)
  1241. >>> inv_boxcox(y, 2.5)
  1242. array([1., 4., 10.])
  1243. """)
  1244. add_newdoc("inv_boxcox1p",
  1245. """
  1246. inv_boxcox1p(y, lmbda, out=None)
  1247. Compute the inverse of the Box-Cox transformation.
  1248. Find ``x`` such that::
  1249. y = ((1+x)**lmbda - 1) / lmbda if lmbda != 0
  1250. log(1+x) if lmbda == 0
  1251. Parameters
  1252. ----------
  1253. y : array_like
  1254. Data to be transformed.
  1255. lmbda : array_like
  1256. Power parameter of the Box-Cox transform.
  1257. out : ndarray, optional
  1258. Optional output array for the function values
  1259. Returns
  1260. -------
  1261. x : scalar or ndarray
  1262. Transformed data.
  1263. Notes
  1264. -----
  1265. .. versionadded:: 0.16.0
  1266. Examples
  1267. --------
  1268. >>> from scipy.special import boxcox1p, inv_boxcox1p
  1269. >>> y = boxcox1p([1, 4, 10], 2.5)
  1270. >>> inv_boxcox1p(y, 2.5)
  1271. array([1., 4., 10.])
  1272. """)
  1273. add_newdoc("btdtr",
  1274. r"""
  1275. btdtr(a, b, x, out=None)
  1276. Cumulative distribution function of the beta distribution.
  1277. Returns the integral from zero to `x` of the beta probability density
  1278. function,
  1279. .. math::
  1280. I = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1}\,dt
  1281. where :math:`\Gamma` is the gamma function.
  1282. Parameters
  1283. ----------
  1284. a : array_like
  1285. Shape parameter (a > 0).
  1286. b : array_like
  1287. Shape parameter (b > 0).
  1288. x : array_like
  1289. Upper limit of integration, in [0, 1].
  1290. out : ndarray, optional
  1291. Optional output array for the function values
  1292. Returns
  1293. -------
  1294. I : scalar or ndarray
  1295. Cumulative distribution function of the beta distribution with
  1296. parameters `a` and `b` at `x`.
  1297. See Also
  1298. --------
  1299. betainc
  1300. Notes
  1301. -----
  1302. This function is identical to the incomplete beta integral function
  1303. `betainc`.
  1304. Wrapper for the Cephes [1]_ routine `btdtr`.
  1305. References
  1306. ----------
  1307. .. [1] Cephes Mathematical Functions Library,
  1308. http://www.netlib.org/cephes/
  1309. """)
  1310. add_newdoc("btdtri",
  1311. r"""
  1312. btdtri(a, b, p, out=None)
  1313. The `p`-th quantile of the beta distribution.
  1314. This function is the inverse of the beta cumulative distribution function,
  1315. `btdtr`, returning the value of `x` for which `btdtr(a, b, x) = p`, or
  1316. .. math::
  1317. p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1}\,dt
  1318. Parameters
  1319. ----------
  1320. a : array_like
  1321. Shape parameter (`a` > 0).
  1322. b : array_like
  1323. Shape parameter (`b` > 0).
  1324. p : array_like
  1325. Cumulative probability, in [0, 1].
  1326. out : ndarray, optional
  1327. Optional output array for the function values
  1328. Returns
  1329. -------
  1330. x : scalar or ndarray
  1331. The quantile corresponding to `p`.
  1332. See Also
  1333. --------
  1334. betaincinv
  1335. btdtr
  1336. Notes
  1337. -----
  1338. The value of `x` is found by interval halving or Newton iterations.
  1339. Wrapper for the Cephes [1]_ routine `incbi`, which solves the equivalent
  1340. problem of finding the inverse of the incomplete beta integral.
  1341. References
  1342. ----------
  1343. .. [1] Cephes Mathematical Functions Library,
  1344. http://www.netlib.org/cephes/
  1345. """)
  1346. add_newdoc("cbrt",
  1347. """
  1348. cbrt(x, out=None)
  1349. Element-wise cube root of `x`.
  1350. Parameters
  1351. ----------
  1352. x : array_like
  1353. `x` must contain real numbers.
  1354. out : ndarray, optional
  1355. Optional output array for the function values
  1356. Returns
  1357. -------
  1358. scalar or ndarray
  1359. The cube root of each value in `x`.
  1360. Examples
  1361. --------
  1362. >>> from scipy.special import cbrt
  1363. >>> cbrt(8)
  1364. 2.0
  1365. >>> cbrt([-8, -3, 0.125, 1.331])
  1366. array([-2. , -1.44224957, 0.5 , 1.1 ])
  1367. """)
  1368. add_newdoc("chdtr",
  1369. r"""
  1370. chdtr(v, x, out=None)
  1371. Chi square cumulative distribution function.
  1372. Returns the area under the left tail (from 0 to `x`) of the Chi
  1373. square probability density function with `v` degrees of freedom:
  1374. .. math::
  1375. \frac{1}{2^{v/2} \Gamma(v/2)} \int_0^x t^{v/2 - 1} e^{-t/2} dt
  1376. Here :math:`\Gamma` is the Gamma function; see `gamma`. This
  1377. integral can be expressed in terms of the regularized lower
  1378. incomplete gamma function `gammainc` as
  1379. ``gammainc(v / 2, x / 2)``. [1]_
  1380. Parameters
  1381. ----------
  1382. v : array_like
  1383. Degrees of freedom.
  1384. x : array_like
  1385. Upper bound of the integral.
  1386. out : ndarray, optional
  1387. Optional output array for the function results.
  1388. Returns
  1389. -------
  1390. scalar or ndarray
  1391. Values of the cumulative distribution function.
  1392. See Also
  1393. --------
  1394. chdtrc, chdtri, chdtriv, gammainc
  1395. References
  1396. ----------
  1397. .. [1] Chi-Square distribution,
  1398. https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  1399. Examples
  1400. --------
  1401. >>> import numpy as np
  1402. >>> import scipy.special as sc
  1403. It can be expressed in terms of the regularized lower incomplete
  1404. gamma function.
  1405. >>> v = 1
  1406. >>> x = np.arange(4)
  1407. >>> sc.chdtr(v, x)
  1408. array([0. , 0.68268949, 0.84270079, 0.91673548])
  1409. >>> sc.gammainc(v / 2, x / 2)
  1410. array([0. , 0.68268949, 0.84270079, 0.91673548])
  1411. """)
  1412. add_newdoc("chdtrc",
  1413. r"""
  1414. chdtrc(v, x, out=None)
  1415. Chi square survival function.
  1416. Returns the area under the right hand tail (from `x` to infinity)
  1417. of the Chi square probability density function with `v` degrees of
  1418. freedom:
  1419. .. math::
  1420. \frac{1}{2^{v/2} \Gamma(v/2)} \int_x^\infty t^{v/2 - 1} e^{-t/2} dt
  1421. Here :math:`\Gamma` is the Gamma function; see `gamma`. This
  1422. integral can be expressed in terms of the regularized upper
  1423. incomplete gamma function `gammaincc` as
  1424. ``gammaincc(v / 2, x / 2)``. [1]_
  1425. Parameters
  1426. ----------
  1427. v : array_like
  1428. Degrees of freedom.
  1429. x : array_like
  1430. Lower bound of the integral.
  1431. out : ndarray, optional
  1432. Optional output array for the function results.
  1433. Returns
  1434. -------
  1435. scalar or ndarray
  1436. Values of the survival function.
  1437. See Also
  1438. --------
  1439. chdtr, chdtri, chdtriv, gammaincc
  1440. References
  1441. ----------
  1442. .. [1] Chi-Square distribution,
  1443. https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  1444. Examples
  1445. --------
  1446. >>> import numpy as np
  1447. >>> import scipy.special as sc
  1448. It can be expressed in terms of the regularized upper incomplete
  1449. gamma function.
  1450. >>> v = 1
  1451. >>> x = np.arange(4)
  1452. >>> sc.chdtrc(v, x)
  1453. array([1. , 0.31731051, 0.15729921, 0.08326452])
  1454. >>> sc.gammaincc(v / 2, x / 2)
  1455. array([1. , 0.31731051, 0.15729921, 0.08326452])
  1456. """)
  1457. add_newdoc("chdtri",
  1458. """
  1459. chdtri(v, p, out=None)
  1460. Inverse to `chdtrc` with respect to `x`.
  1461. Returns `x` such that ``chdtrc(v, x) == p``.
  1462. Parameters
  1463. ----------
  1464. v : array_like
  1465. Degrees of freedom.
  1466. p : array_like
  1467. Probability.
  1468. out : ndarray, optional
  1469. Optional output array for the function results.
  1470. Returns
  1471. -------
  1472. x : scalar or ndarray
  1473. Value so that the probability a Chi square random variable
  1474. with `v` degrees of freedom is greater than `x` equals `p`.
  1475. See Also
  1476. --------
  1477. chdtrc, chdtr, chdtriv
  1478. References
  1479. ----------
  1480. .. [1] Chi-Square distribution,
  1481. https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  1482. Examples
  1483. --------
  1484. >>> import scipy.special as sc
  1485. It inverts `chdtrc`.
  1486. >>> v, p = 1, 0.3
  1487. >>> sc.chdtrc(v, sc.chdtri(v, p))
  1488. 0.3
  1489. >>> x = 1
  1490. >>> sc.chdtri(v, sc.chdtrc(v, x))
  1491. 1.0
  1492. """)
  1493. add_newdoc("chdtriv",
  1494. """
  1495. chdtriv(p, x, out=None)
  1496. Inverse to `chdtr` with respect to `v`.
  1497. Returns `v` such that ``chdtr(v, x) == p``.
  1498. Parameters
  1499. ----------
  1500. p : array_like
  1501. Probability that the Chi square random variable is less than
  1502. or equal to `x`.
  1503. x : array_like
  1504. Nonnegative input.
  1505. out : ndarray, optional
  1506. Optional output array for the function results.
  1507. Returns
  1508. -------
  1509. scalar or ndarray
  1510. Degrees of freedom.
  1511. See Also
  1512. --------
  1513. chdtr, chdtrc, chdtri
  1514. References
  1515. ----------
  1516. .. [1] Chi-Square distribution,
  1517. https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  1518. Examples
  1519. --------
  1520. >>> import scipy.special as sc
  1521. It inverts `chdtr`.
  1522. >>> p, x = 0.5, 1
  1523. >>> sc.chdtr(sc.chdtriv(p, x), x)
  1524. 0.5000000000202172
  1525. >>> v = 1
  1526. >>> sc.chdtriv(sc.chdtr(v, x), v)
  1527. 1.0000000000000013
  1528. """)
  1529. add_newdoc("chndtr",
  1530. r"""
  1531. chndtr(x, df, nc, out=None)
  1532. Non-central chi square cumulative distribution function
  1533. The cumulative distribution function is given by:
  1534. .. math::
  1535. P(\chi^{\prime 2} \vert \nu, \lambda) =\sum_{j=0}^{\infty}
  1536. e^{-\lambda /2}
  1537. \frac{(\lambda /2)^j}{j!} P(\chi^{\prime 2} \vert \nu + 2j),
  1538. where :math:`\nu > 0` is the degrees of freedom (``df``) and
  1539. :math:`\lambda \geq 0` is the non-centrality parameter (``nc``).
  1540. Parameters
  1541. ----------
  1542. x : array_like
  1543. Upper bound of the integral; must satisfy ``x >= 0``
  1544. df : array_like
  1545. Degrees of freedom; must satisfy ``df > 0``
  1546. nc : array_like
  1547. Non-centrality parameter; must satisfy ``nc >= 0``
  1548. out : ndarray, optional
  1549. Optional output array for the function results
  1550. Returns
  1551. -------
  1552. x : scalar or ndarray
  1553. Value of the non-central chi square cumulative distribution function.
  1554. See Also
  1555. --------
  1556. chndtrix, chndtridf, chndtrinc
  1557. """)
  1558. add_newdoc("chndtrix",
  1559. """
  1560. chndtrix(p, df, nc, out=None)
  1561. Inverse to `chndtr` vs `x`
  1562. Calculated using a search to find a value for `x` that produces the
  1563. desired value of `p`.
  1564. Parameters
  1565. ----------
  1566. p : array_like
  1567. Probability; must satisfy ``0 <= p < 1``
  1568. df : array_like
  1569. Degrees of freedom; must satisfy ``df > 0``
  1570. nc : array_like
  1571. Non-centrality parameter; must satisfy ``nc >= 0``
  1572. out : ndarray, optional
  1573. Optional output array for the function results
  1574. Returns
  1575. -------
  1576. x : scalar or ndarray
  1577. Value so that the probability a non-central Chi square random variable
  1578. with `df` degrees of freedom and non-centrality, `nc`, is greater than
  1579. `x` equals `p`.
  1580. See Also
  1581. --------
  1582. chndtr, chndtridf, chndtrinc
  1583. """)
  1584. add_newdoc("chndtridf",
  1585. """
  1586. chndtridf(x, p, nc, out=None)
  1587. Inverse to `chndtr` vs `df`
  1588. Calculated using a search to find a value for `df` that produces the
  1589. desired value of `p`.
  1590. Parameters
  1591. ----------
  1592. x : array_like
  1593. Upper bound of the integral; must satisfy ``x >= 0``
  1594. p : array_like
  1595. Probability; must satisfy ``0 <= p < 1``
  1596. nc : array_like
  1597. Non-centrality parameter; must satisfy ``nc >= 0``
  1598. out : ndarray, optional
  1599. Optional output array for the function results
  1600. Returns
  1601. -------
  1602. df : scalar or ndarray
  1603. Degrees of freedom
  1604. See Also
  1605. --------
  1606. chndtr, chndtrix, chndtrinc
  1607. """)
  1608. add_newdoc("chndtrinc",
  1609. """
  1610. chndtrinc(x, df, p, out=None)
  1611. Inverse to `chndtr` vs `nc`
  1612. Calculated using a search to find a value for `df` that produces the
  1613. desired value of `p`.
  1614. Parameters
  1615. ----------
  1616. x : array_like
  1617. Upper bound of the integral; must satisfy ``x >= 0``
  1618. df : array_like
  1619. Degrees of freedom; must satisfy ``df > 0``
  1620. p : array_like
  1621. Probability; must satisfy ``0 <= p < 1``
  1622. out : ndarray, optional
  1623. Optional output array for the function results
  1624. Returns
  1625. -------
  1626. nc : scalar or ndarray
  1627. Non-centrality
  1628. See Also
  1629. --------
  1630. chndtr, chndtrix, chndtrinc
  1631. """)
  1632. add_newdoc("cosdg",
  1633. """
  1634. cosdg(x, out=None)
  1635. Cosine of the angle `x` given in degrees.
  1636. Parameters
  1637. ----------
  1638. x : array_like
  1639. Angle, given in degrees.
  1640. out : ndarray, optional
  1641. Optional output array for the function results.
  1642. Returns
  1643. -------
  1644. scalar or ndarray
  1645. Cosine of the input.
  1646. See Also
  1647. --------
  1648. sindg, tandg, cotdg
  1649. Examples
  1650. --------
  1651. >>> import numpy as np
  1652. >>> import scipy.special as sc
  1653. It is more accurate than using cosine directly.
  1654. >>> x = 90 + 180 * np.arange(3)
  1655. >>> sc.cosdg(x)
  1656. array([-0., 0., -0.])
  1657. >>> np.cos(x * np.pi / 180)
  1658. array([ 6.1232340e-17, -1.8369702e-16, 3.0616170e-16])
  1659. """)
  1660. add_newdoc("cosm1",
  1661. """
  1662. cosm1(x, out=None)
  1663. cos(x) - 1 for use when `x` is near zero.
  1664. Parameters
  1665. ----------
  1666. x : array_like
  1667. Real valued argument.
  1668. out : ndarray, optional
  1669. Optional output array for the function results.
  1670. Returns
  1671. -------
  1672. scalar or ndarray
  1673. Values of ``cos(x) - 1``.
  1674. See Also
  1675. --------
  1676. expm1, log1p
  1677. Examples
  1678. --------
  1679. >>> import numpy as np
  1680. >>> import scipy.special as sc
  1681. It is more accurate than computing ``cos(x) - 1`` directly for
  1682. ``x`` around 0.
  1683. >>> x = 1e-30
  1684. >>> np.cos(x) - 1
  1685. 0.0
  1686. >>> sc.cosm1(x)
  1687. -5.0000000000000005e-61
  1688. """)
  1689. add_newdoc("cotdg",
  1690. """
  1691. cotdg(x, out=None)
  1692. Cotangent of the angle `x` given in degrees.
  1693. Parameters
  1694. ----------
  1695. x : array_like
  1696. Angle, given in degrees.
  1697. out : ndarray, optional
  1698. Optional output array for the function results.
  1699. Returns
  1700. -------
  1701. scalar or ndarray
  1702. Cotangent at the input.
  1703. See Also
  1704. --------
  1705. sindg, cosdg, tandg
  1706. Examples
  1707. --------
  1708. >>> import numpy as np
  1709. >>> import scipy.special as sc
  1710. It is more accurate than using cotangent directly.
  1711. >>> x = 90 + 180 * np.arange(3)
  1712. >>> sc.cotdg(x)
  1713. array([0., 0., 0.])
  1714. >>> 1 / np.tan(x * np.pi / 180)
  1715. array([6.1232340e-17, 1.8369702e-16, 3.0616170e-16])
  1716. """)
  1717. add_newdoc("dawsn",
  1718. """
  1719. dawsn(x, out=None)
  1720. Dawson's integral.
  1721. Computes::
  1722. exp(-x**2) * integral(exp(t**2), t=0..x).
  1723. Parameters
  1724. ----------
  1725. x : array_like
  1726. Function parameter.
  1727. out : ndarray, optional
  1728. Optional output array for the function values
  1729. Returns
  1730. -------
  1731. y : scalar or ndarray
  1732. Value of the integral.
  1733. See Also
  1734. --------
  1735. wofz, erf, erfc, erfcx, erfi
  1736. References
  1737. ----------
  1738. .. [1] Steven G. Johnson, Faddeeva W function implementation.
  1739. http://ab-initio.mit.edu/Faddeeva
  1740. Examples
  1741. --------
  1742. >>> import numpy as np
  1743. >>> from scipy import special
  1744. >>> import matplotlib.pyplot as plt
  1745. >>> x = np.linspace(-15, 15, num=1000)
  1746. >>> plt.plot(x, special.dawsn(x))
  1747. >>> plt.xlabel('$x$')
  1748. >>> plt.ylabel('$dawsn(x)$')
  1749. >>> plt.show()
  1750. """)
  1751. add_newdoc("ellipe",
  1752. r"""
  1753. ellipe(m, out=None)
  1754. Complete elliptic integral of the second kind
  1755. This function is defined as
  1756. .. math:: E(m) = \int_0^{\pi/2} [1 - m \sin(t)^2]^{1/2} dt
  1757. Parameters
  1758. ----------
  1759. m : array_like
  1760. Defines the parameter of the elliptic integral.
  1761. out : ndarray, optional
  1762. Optional output array for the function values
  1763. Returns
  1764. -------
  1765. E : scalar or ndarray
  1766. Value of the elliptic integral.
  1767. Notes
  1768. -----
  1769. Wrapper for the Cephes [1]_ routine `ellpe`.
  1770. For `m > 0` the computation uses the approximation,
  1771. .. math:: E(m) \approx P(1-m) - (1-m) \log(1-m) Q(1-m),
  1772. where :math:`P` and :math:`Q` are tenth-order polynomials. For
  1773. `m < 0`, the relation
  1774. .. math:: E(m) = E(m/(m - 1)) \sqrt(1-m)
  1775. is used.
  1776. The parameterization in terms of :math:`m` follows that of section
  1777. 17.2 in [2]_. Other parameterizations in terms of the
  1778. complementary parameter :math:`1 - m`, modular angle
  1779. :math:`\sin^2(\alpha) = m`, or modulus :math:`k^2 = m` are also
  1780. used, so be careful that you choose the correct parameter.
  1781. The Legendre E integral is related to Carlson's symmetric R_D or R_G
  1782. functions in multiple ways [3]_. For example,
  1783. .. math:: E(m) = 2 R_G(0, 1-k^2, 1) .
  1784. See Also
  1785. --------
  1786. ellipkm1 : Complete elliptic integral of the first kind, near `m` = 1
  1787. ellipk : Complete elliptic integral of the first kind
  1788. ellipkinc : Incomplete elliptic integral of the first kind
  1789. ellipeinc : Incomplete elliptic integral of the second kind
  1790. elliprd : Symmetric elliptic integral of the second kind.
  1791. elliprg : Completely-symmetric elliptic integral of the second kind.
  1792. References
  1793. ----------
  1794. .. [1] Cephes Mathematical Functions Library,
  1795. http://www.netlib.org/cephes/
  1796. .. [2] Milton Abramowitz and Irene A. Stegun, eds.
  1797. Handbook of Mathematical Functions with Formulas,
  1798. Graphs, and Mathematical Tables. New York: Dover, 1972.
  1799. .. [3] NIST Digital Library of Mathematical
  1800. Functions. http://dlmf.nist.gov/, Release 1.0.28 of
  1801. 2020-09-15. See Sec. 19.25(i) https://dlmf.nist.gov/19.25#i
  1802. Examples
  1803. --------
  1804. This function is used in finding the circumference of an
  1805. ellipse with semi-major axis `a` and semi-minor axis `b`.
  1806. >>> import numpy as np
  1807. >>> from scipy import special
  1808. >>> a = 3.5
  1809. >>> b = 2.1
  1810. >>> e_sq = 1.0 - b**2/a**2 # eccentricity squared
  1811. Then the circumference is found using the following:
  1812. >>> C = 4*a*special.ellipe(e_sq) # circumference formula
  1813. >>> C
  1814. 17.868899204378693
  1815. When `a` and `b` are the same (meaning eccentricity is 0),
  1816. this reduces to the circumference of a circle.
  1817. >>> 4*a*special.ellipe(0.0) # formula for ellipse with a = b
  1818. 21.991148575128552
  1819. >>> 2*np.pi*a # formula for circle of radius a
  1820. 21.991148575128552
  1821. """)
  1822. add_newdoc("ellipeinc",
  1823. r"""
  1824. ellipeinc(phi, m, out=None)
  1825. Incomplete elliptic integral of the second kind
  1826. This function is defined as
  1827. .. math:: E(\phi, m) = \int_0^{\phi} [1 - m \sin(t)^2]^{1/2} dt
  1828. Parameters
  1829. ----------
  1830. phi : array_like
  1831. amplitude of the elliptic integral.
  1832. m : array_like
  1833. parameter of the elliptic integral.
  1834. out : ndarray, optional
  1835. Optional output array for the function values
  1836. Returns
  1837. -------
  1838. E : scalar or ndarray
  1839. Value of the elliptic integral.
  1840. Notes
  1841. -----
  1842. Wrapper for the Cephes [1]_ routine `ellie`.
  1843. Computation uses arithmetic-geometric means algorithm.
  1844. The parameterization in terms of :math:`m` follows that of section
  1845. 17.2 in [2]_. Other parameterizations in terms of the
  1846. complementary parameter :math:`1 - m`, modular angle
  1847. :math:`\sin^2(\alpha) = m`, or modulus :math:`k^2 = m` are also
  1848. used, so be careful that you choose the correct parameter.
  1849. The Legendre E incomplete integral can be related to combinations
  1850. of Carlson's symmetric integrals R_D, R_F, and R_G in multiple
  1851. ways [3]_. For example, with :math:`c = \csc^2\phi`,
  1852. .. math::
  1853. E(\phi, m) = R_F(c-1, c-k^2, c)
  1854. - \frac{1}{3} k^2 R_D(c-1, c-k^2, c) .
  1855. See Also
  1856. --------
  1857. ellipkm1 : Complete elliptic integral of the first kind, near `m` = 1
  1858. ellipk : Complete elliptic integral of the first kind
  1859. ellipkinc : Incomplete elliptic integral of the first kind
  1860. ellipe : Complete elliptic integral of the second kind
  1861. elliprd : Symmetric elliptic integral of the second kind.
  1862. elliprf : Completely-symmetric elliptic integral of the first kind.
  1863. elliprg : Completely-symmetric elliptic integral of the second kind.
  1864. References
  1865. ----------
  1866. .. [1] Cephes Mathematical Functions Library,
  1867. http://www.netlib.org/cephes/
  1868. .. [2] Milton Abramowitz and Irene A. Stegun, eds.
  1869. Handbook of Mathematical Functions with Formulas,
  1870. Graphs, and Mathematical Tables. New York: Dover, 1972.
  1871. .. [3] NIST Digital Library of Mathematical
  1872. Functions. http://dlmf.nist.gov/, Release 1.0.28 of
  1873. 2020-09-15. See Sec. 19.25(i) https://dlmf.nist.gov/19.25#i
  1874. """)
  1875. add_newdoc("ellipj",
  1876. """
  1877. ellipj(u, m, out=None)
  1878. Jacobian elliptic functions
  1879. Calculates the Jacobian elliptic functions of parameter `m` between
  1880. 0 and 1, and real argument `u`.
  1881. Parameters
  1882. ----------
  1883. m : array_like
  1884. Parameter.
  1885. u : array_like
  1886. Argument.
  1887. out : tuple of ndarray, optional
  1888. Optional output arrays for the function values
  1889. Returns
  1890. -------
  1891. sn, cn, dn, ph : 4-tuple of scalar or ndarray
  1892. The returned functions::
  1893. sn(u|m), cn(u|m), dn(u|m)
  1894. The value `ph` is such that if `u = ellipkinc(ph, m)`,
  1895. then `sn(u|m) = sin(ph)` and `cn(u|m) = cos(ph)`.
  1896. Notes
  1897. -----
  1898. Wrapper for the Cephes [1]_ routine `ellpj`.
  1899. These functions are periodic, with quarter-period on the real axis
  1900. equal to the complete elliptic integral `ellipk(m)`.
  1901. Relation to incomplete elliptic integral: If `u = ellipkinc(phi,m)`, then
  1902. `sn(u|m) = sin(phi)`, and `cn(u|m) = cos(phi)`. The `phi` is called
  1903. the amplitude of `u`.
  1904. Computation is by means of the arithmetic-geometric mean algorithm,
  1905. except when `m` is within 1e-9 of 0 or 1. In the latter case with `m`
  1906. close to 1, the approximation applies only for `phi < pi/2`.
  1907. See also
  1908. --------
  1909. ellipk : Complete elliptic integral of the first kind
  1910. ellipkinc : Incomplete elliptic integral of the first kind
  1911. References
  1912. ----------
  1913. .. [1] Cephes Mathematical Functions Library,
  1914. http://www.netlib.org/cephes/
  1915. """)
  1916. add_newdoc("ellipkm1",
  1917. """
  1918. ellipkm1(p, out=None)
  1919. Complete elliptic integral of the first kind around `m` = 1
  1920. This function is defined as
  1921. .. math:: K(p) = \\int_0^{\\pi/2} [1 - m \\sin(t)^2]^{-1/2} dt
  1922. where `m = 1 - p`.
  1923. Parameters
  1924. ----------
  1925. p : array_like
  1926. Defines the parameter of the elliptic integral as `m = 1 - p`.
  1927. out : ndarray, optional
  1928. Optional output array for the function values
  1929. Returns
  1930. -------
  1931. K : scalar or ndarray
  1932. Value of the elliptic integral.
  1933. Notes
  1934. -----
  1935. Wrapper for the Cephes [1]_ routine `ellpk`.
  1936. For `p <= 1`, computation uses the approximation,
  1937. .. math:: K(p) \\approx P(p) - \\log(p) Q(p),
  1938. where :math:`P` and :math:`Q` are tenth-order polynomials. The
  1939. argument `p` is used internally rather than `m` so that the logarithmic
  1940. singularity at `m = 1` will be shifted to the origin; this preserves
  1941. maximum accuracy. For `p > 1`, the identity
  1942. .. math:: K(p) = K(1/p)/\\sqrt(p)
  1943. is used.
  1944. See Also
  1945. --------
  1946. ellipk : Complete elliptic integral of the first kind
  1947. ellipkinc : Incomplete elliptic integral of the first kind
  1948. ellipe : Complete elliptic integral of the second kind
  1949. ellipeinc : Incomplete elliptic integral of the second kind
  1950. elliprf : Completely-symmetric elliptic integral of the first kind.
  1951. References
  1952. ----------
  1953. .. [1] Cephes Mathematical Functions Library,
  1954. http://www.netlib.org/cephes/
  1955. """)
  1956. add_newdoc("ellipk",
  1957. r"""
  1958. ellipk(m, out=None)
  1959. Complete elliptic integral of the first kind.
  1960. This function is defined as
  1961. .. math:: K(m) = \int_0^{\pi/2} [1 - m \sin(t)^2]^{-1/2} dt
  1962. Parameters
  1963. ----------
  1964. m : array_like
  1965. The parameter of the elliptic integral.
  1966. out : ndarray, optional
  1967. Optional output array for the function values
  1968. Returns
  1969. -------
  1970. K : scalar or ndarray
  1971. Value of the elliptic integral.
  1972. Notes
  1973. -----
  1974. For more precision around point m = 1, use `ellipkm1`, which this
  1975. function calls.
  1976. The parameterization in terms of :math:`m` follows that of section
  1977. 17.2 in [1]_. Other parameterizations in terms of the
  1978. complementary parameter :math:`1 - m`, modular angle
  1979. :math:`\sin^2(\alpha) = m`, or modulus :math:`k^2 = m` are also
  1980. used, so be careful that you choose the correct parameter.
  1981. The Legendre K integral is related to Carlson's symmetric R_F
  1982. function by [2]_:
  1983. .. math:: K(m) = R_F(0, 1-k^2, 1) .
  1984. See Also
  1985. --------
  1986. ellipkm1 : Complete elliptic integral of the first kind around m = 1
  1987. ellipkinc : Incomplete elliptic integral of the first kind
  1988. ellipe : Complete elliptic integral of the second kind
  1989. ellipeinc : Incomplete elliptic integral of the second kind
  1990. elliprf : Completely-symmetric elliptic integral of the first kind.
  1991. References
  1992. ----------
  1993. .. [1] Milton Abramowitz and Irene A. Stegun, eds.
  1994. Handbook of Mathematical Functions with Formulas,
  1995. Graphs, and Mathematical Tables. New York: Dover, 1972.
  1996. .. [2] NIST Digital Library of Mathematical
  1997. Functions. http://dlmf.nist.gov/, Release 1.0.28 of
  1998. 2020-09-15. See Sec. 19.25(i) https://dlmf.nist.gov/19.25#i
  1999. """)
  2000. add_newdoc("ellipkinc",
  2001. r"""
  2002. ellipkinc(phi, m, out=None)
  2003. Incomplete elliptic integral of the first kind
  2004. This function is defined as
  2005. .. math:: K(\phi, m) = \int_0^{\phi} [1 - m \sin(t)^2]^{-1/2} dt
  2006. This function is also called :math:`F(\phi, m)`.
  2007. Parameters
  2008. ----------
  2009. phi : array_like
  2010. amplitude of the elliptic integral
  2011. m : array_like
  2012. parameter of the elliptic integral
  2013. out : ndarray, optional
  2014. Optional output array for the function values
  2015. Returns
  2016. -------
  2017. K : scalar or ndarray
  2018. Value of the elliptic integral
  2019. Notes
  2020. -----
  2021. Wrapper for the Cephes [1]_ routine `ellik`. The computation is
  2022. carried out using the arithmetic-geometric mean algorithm.
  2023. The parameterization in terms of :math:`m` follows that of section
  2024. 17.2 in [2]_. Other parameterizations in terms of the
  2025. complementary parameter :math:`1 - m`, modular angle
  2026. :math:`\sin^2(\alpha) = m`, or modulus :math:`k^2 = m` are also
  2027. used, so be careful that you choose the correct parameter.
  2028. The Legendre K incomplete integral (or F integral) is related to
  2029. Carlson's symmetric R_F function [3]_.
  2030. Setting :math:`c = \csc^2\phi`,
  2031. .. math:: F(\phi, m) = R_F(c-1, c-k^2, c) .
  2032. See Also
  2033. --------
  2034. ellipkm1 : Complete elliptic integral of the first kind, near `m` = 1
  2035. ellipk : Complete elliptic integral of the first kind
  2036. ellipe : Complete elliptic integral of the second kind
  2037. ellipeinc : Incomplete elliptic integral of the second kind
  2038. elliprf : Completely-symmetric elliptic integral of the first kind.
  2039. References
  2040. ----------
  2041. .. [1] Cephes Mathematical Functions Library,
  2042. http://www.netlib.org/cephes/
  2043. .. [2] Milton Abramowitz and Irene A. Stegun, eds.
  2044. Handbook of Mathematical Functions with Formulas,
  2045. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2046. .. [3] NIST Digital Library of Mathematical
  2047. Functions. http://dlmf.nist.gov/, Release 1.0.28 of
  2048. 2020-09-15. See Sec. 19.25(i) https://dlmf.nist.gov/19.25#i
  2049. """)
  2050. add_newdoc(
  2051. "elliprc",
  2052. r"""
  2053. elliprc(x, y, out=None)
  2054. Degenerate symmetric elliptic integral.
  2055. The function RC is defined as [1]_
  2056. .. math::
  2057. R_{\mathrm{C}}(x, y) =
  2058. \frac{1}{2} \int_0^{+\infty} (t + x)^{-1/2} (t + y)^{-1} dt
  2059. = R_{\mathrm{F}}(x, y, y)
  2060. Parameters
  2061. ----------
  2062. x, y : array_like
  2063. Real or complex input parameters. `x` can be any number in the
  2064. complex plane cut along the negative real axis. `y` must be non-zero.
  2065. out : ndarray, optional
  2066. Optional output array for the function values
  2067. Returns
  2068. -------
  2069. R : scalar or ndarray
  2070. Value of the integral. If `y` is real and negative, the Cauchy
  2071. principal value is returned. If both of `x` and `y` are real, the
  2072. return value is real. Otherwise, the return value is complex.
  2073. Notes
  2074. -----
  2075. RC is a degenerate case of the symmetric integral RF: ``elliprc(x, y) ==
  2076. elliprf(x, y, y)``. It is an elementary function rather than an elliptic
  2077. integral.
  2078. The code implements Carlson's algorithm based on the duplication theorems
  2079. and series expansion up to the 7th order. [2]_
  2080. .. versionadded:: 1.8.0
  2081. See Also
  2082. --------
  2083. elliprf : Completely-symmetric elliptic integral of the first kind.
  2084. elliprd : Symmetric elliptic integral of the second kind.
  2085. elliprg : Completely-symmetric elliptic integral of the second kind.
  2086. elliprj : Symmetric elliptic integral of the third kind.
  2087. References
  2088. ----------
  2089. .. [1] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
  2090. Functions," NIST, US Dept. of Commerce.
  2091. https://dlmf.nist.gov/19.16.E6
  2092. .. [2] B. C. Carlson, "Numerical computation of real or complex elliptic
  2093. integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
  2094. https://arxiv.org/abs/math/9409227
  2095. https://doi.org/10.1007/BF02198293
  2096. Examples
  2097. --------
  2098. Basic homogeneity property:
  2099. >>> import numpy as np
  2100. >>> from scipy.special import elliprc
  2101. >>> x = 1.2 + 3.4j
  2102. >>> y = 5.
  2103. >>> scale = 0.3 + 0.4j
  2104. >>> elliprc(scale*x, scale*y)
  2105. (0.5484493976710874-0.4169557678995833j)
  2106. >>> elliprc(x, y)/np.sqrt(scale)
  2107. (0.5484493976710874-0.41695576789958333j)
  2108. When the two arguments coincide, the integral is particularly
  2109. simple:
  2110. >>> x = 1.2 + 3.4j
  2111. >>> elliprc(x, x)
  2112. (0.4299173120614631-0.3041729818745595j)
  2113. >>> 1/np.sqrt(x)
  2114. (0.4299173120614631-0.30417298187455954j)
  2115. Another simple case: the first argument vanishes:
  2116. >>> y = 1.2 + 3.4j
  2117. >>> elliprc(0, y)
  2118. (0.6753125346116815-0.47779380263880866j)
  2119. >>> np.pi/2/np.sqrt(y)
  2120. (0.6753125346116815-0.4777938026388088j)
  2121. When `x` and `y` are both positive, we can express
  2122. :math:`R_C(x,y)` in terms of more elementary functions. For the
  2123. case :math:`0 \le x < y`,
  2124. >>> x = 3.2
  2125. >>> y = 6.
  2126. >>> elliprc(x, y)
  2127. 0.44942991498453444
  2128. >>> np.arctan(np.sqrt((y-x)/x))/np.sqrt(y-x)
  2129. 0.44942991498453433
  2130. And for the case :math:`0 \le y < x`,
  2131. >>> x = 6.
  2132. >>> y = 3.2
  2133. >>> elliprc(x,y)
  2134. 0.4989837501576147
  2135. >>> np.log((np.sqrt(x)+np.sqrt(x-y))/np.sqrt(y))/np.sqrt(x-y)
  2136. 0.49898375015761476
  2137. """)
  2138. add_newdoc(
  2139. "elliprd",
  2140. r"""
  2141. elliprd(x, y, z, out=None)
  2142. Symmetric elliptic integral of the second kind.
  2143. The function RD is defined as [1]_
  2144. .. math::
  2145. R_{\mathrm{D}}(x, y, z) =
  2146. \frac{3}{2} \int_0^{+\infty} [(t + x) (t + y)]^{-1/2} (t + z)^{-3/2}
  2147. dt
  2148. Parameters
  2149. ----------
  2150. x, y, z : array_like
  2151. Real or complex input parameters. `x` or `y` can be any number in the
  2152. complex plane cut along the negative real axis, but at most one of them
  2153. can be zero, while `z` must be non-zero.
  2154. out : ndarray, optional
  2155. Optional output array for the function values
  2156. Returns
  2157. -------
  2158. R : scalar or ndarray
  2159. Value of the integral. If all of `x`, `y`, and `z` are real, the
  2160. return value is real. Otherwise, the return value is complex.
  2161. Notes
  2162. -----
  2163. RD is a degenerate case of the elliptic integral RJ: ``elliprd(x, y, z) ==
  2164. elliprj(x, y, z, z)``.
  2165. The code implements Carlson's algorithm based on the duplication theorems
  2166. and series expansion up to the 7th order. [2]_
  2167. .. versionadded:: 1.8.0
  2168. See Also
  2169. --------
  2170. elliprc : Degenerate symmetric elliptic integral.
  2171. elliprf : Completely-symmetric elliptic integral of the first kind.
  2172. elliprg : Completely-symmetric elliptic integral of the second kind.
  2173. elliprj : Symmetric elliptic integral of the third kind.
  2174. References
  2175. ----------
  2176. .. [1] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
  2177. Functions," NIST, US Dept. of Commerce.
  2178. https://dlmf.nist.gov/19.16.E5
  2179. .. [2] B. C. Carlson, "Numerical computation of real or complex elliptic
  2180. integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
  2181. https://arxiv.org/abs/math/9409227
  2182. https://doi.org/10.1007/BF02198293
  2183. Examples
  2184. --------
  2185. Basic homogeneity property:
  2186. >>> import numpy as np
  2187. >>> from scipy.special import elliprd
  2188. >>> x = 1.2 + 3.4j
  2189. >>> y = 5.
  2190. >>> z = 6.
  2191. >>> scale = 0.3 + 0.4j
  2192. >>> elliprd(scale*x, scale*y, scale*z)
  2193. (-0.03703043835680379-0.24500934665683802j)
  2194. >>> elliprd(x, y, z)*np.power(scale, -1.5)
  2195. (-0.0370304383568038-0.24500934665683805j)
  2196. All three arguments coincide:
  2197. >>> x = 1.2 + 3.4j
  2198. >>> elliprd(x, x, x)
  2199. (-0.03986825876151896-0.14051741840449586j)
  2200. >>> np.power(x, -1.5)
  2201. (-0.03986825876151894-0.14051741840449583j)
  2202. The so-called "second lemniscate constant":
  2203. >>> elliprd(0, 2, 1)/3
  2204. 0.5990701173677961
  2205. >>> from scipy.special import gamma
  2206. >>> gamma(0.75)**2/np.sqrt(2*np.pi)
  2207. 0.5990701173677959
  2208. """)
  2209. add_newdoc(
  2210. "elliprf",
  2211. r"""
  2212. elliprf(x, y, z, out=None)
  2213. Completely-symmetric elliptic integral of the first kind.
  2214. The function RF is defined as [1]_
  2215. .. math::
  2216. R_{\mathrm{F}}(x, y, z) =
  2217. \frac{1}{2} \int_0^{+\infty} [(t + x) (t + y) (t + z)]^{-1/2} dt
  2218. Parameters
  2219. ----------
  2220. x, y, z : array_like
  2221. Real or complex input parameters. `x`, `y`, or `z` can be any number in
  2222. the complex plane cut along the negative real axis, but at most one of
  2223. them can be zero.
  2224. out : ndarray, optional
  2225. Optional output array for the function values
  2226. Returns
  2227. -------
  2228. R : scalar or ndarray
  2229. Value of the integral. If all of `x`, `y`, and `z` are real, the return
  2230. value is real. Otherwise, the return value is complex.
  2231. Notes
  2232. -----
  2233. The code implements Carlson's algorithm based on the duplication theorems
  2234. and series expansion up to the 7th order (cf.:
  2235. https://dlmf.nist.gov/19.36.i) and the AGM algorithm for the complete
  2236. integral. [2]_
  2237. .. versionadded:: 1.8.0
  2238. See Also
  2239. --------
  2240. elliprc : Degenerate symmetric integral.
  2241. elliprd : Symmetric elliptic integral of the second kind.
  2242. elliprg : Completely-symmetric elliptic integral of the second kind.
  2243. elliprj : Symmetric elliptic integral of the third kind.
  2244. References
  2245. ----------
  2246. .. [1] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
  2247. Functions," NIST, US Dept. of Commerce.
  2248. https://dlmf.nist.gov/19.16.E1
  2249. .. [2] B. C. Carlson, "Numerical computation of real or complex elliptic
  2250. integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
  2251. https://arxiv.org/abs/math/9409227
  2252. https://doi.org/10.1007/BF02198293
  2253. Examples
  2254. --------
  2255. Basic homogeneity property:
  2256. >>> import numpy as np
  2257. >>> from scipy.special import elliprf
  2258. >>> x = 1.2 + 3.4j
  2259. >>> y = 5.
  2260. >>> z = 6.
  2261. >>> scale = 0.3 + 0.4j
  2262. >>> elliprf(scale*x, scale*y, scale*z)
  2263. (0.5328051227278146-0.4008623567957094j)
  2264. >>> elliprf(x, y, z)/np.sqrt(scale)
  2265. (0.5328051227278147-0.4008623567957095j)
  2266. All three arguments coincide:
  2267. >>> x = 1.2 + 3.4j
  2268. >>> elliprf(x, x, x)
  2269. (0.42991731206146316-0.30417298187455954j)
  2270. >>> 1/np.sqrt(x)
  2271. (0.4299173120614631-0.30417298187455954j)
  2272. The so-called "first lemniscate constant":
  2273. >>> elliprf(0, 1, 2)
  2274. 1.3110287771460598
  2275. >>> from scipy.special import gamma
  2276. >>> gamma(0.25)**2/(4*np.sqrt(2*np.pi))
  2277. 1.3110287771460598
  2278. """)
  2279. add_newdoc(
  2280. "elliprg",
  2281. r"""
  2282. elliprg(x, y, z, out=None)
  2283. Completely-symmetric elliptic integral of the second kind.
  2284. The function RG is defined as [1]_
  2285. .. math::
  2286. R_{\mathrm{G}}(x, y, z) =
  2287. \frac{1}{4} \int_0^{+\infty} [(t + x) (t + y) (t + z)]^{-1/2}
  2288. \left(\frac{x}{t + x} + \frac{y}{t + y} + \frac{z}{t + z}\right) t
  2289. dt
  2290. Parameters
  2291. ----------
  2292. x, y, z : array_like
  2293. Real or complex input parameters. `x`, `y`, or `z` can be any number in
  2294. the complex plane cut along the negative real axis.
  2295. out : ndarray, optional
  2296. Optional output array for the function values
  2297. Returns
  2298. -------
  2299. R : scalar or ndarray
  2300. Value of the integral. If all of `x`, `y`, and `z` are real, the return
  2301. value is real. Otherwise, the return value is complex.
  2302. Notes
  2303. -----
  2304. The implementation uses the relation [1]_
  2305. .. math::
  2306. 2 R_{\mathrm{G}}(x, y, z) =
  2307. z R_{\mathrm{F}}(x, y, z) -
  2308. \frac{1}{3} (x - z) (y - z) R_{\mathrm{D}}(x, y, z) +
  2309. \sqrt{\frac{x y}{z}}
  2310. and the symmetry of `x`, `y`, `z` when at least one non-zero parameter can
  2311. be chosen as the pivot. When one of the arguments is close to zero, the AGM
  2312. method is applied instead. Other special cases are computed following Ref.
  2313. [2]_
  2314. .. versionadded:: 1.8.0
  2315. See Also
  2316. --------
  2317. elliprc : Degenerate symmetric integral.
  2318. elliprd : Symmetric elliptic integral of the second kind.
  2319. elliprf : Completely-symmetric elliptic integral of the first kind.
  2320. elliprj : Symmetric elliptic integral of the third kind.
  2321. References
  2322. ----------
  2323. .. [1] B. C. Carlson, "Numerical computation of real or complex elliptic
  2324. integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
  2325. https://arxiv.org/abs/math/9409227
  2326. https://doi.org/10.1007/BF02198293
  2327. .. [2] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
  2328. Functions," NIST, US Dept. of Commerce.
  2329. https://dlmf.nist.gov/19.16.E1
  2330. https://dlmf.nist.gov/19.20.ii
  2331. Examples
  2332. --------
  2333. Basic homogeneity property:
  2334. >>> import numpy as np
  2335. >>> from scipy.special import elliprg
  2336. >>> x = 1.2 + 3.4j
  2337. >>> y = 5.
  2338. >>> z = 6.
  2339. >>> scale = 0.3 + 0.4j
  2340. >>> elliprg(scale*x, scale*y, scale*z)
  2341. (1.195936862005246+0.8470988320464167j)
  2342. >>> elliprg(x, y, z)*np.sqrt(scale)
  2343. (1.195936862005246+0.8470988320464165j)
  2344. Simplifications:
  2345. >>> elliprg(0, y, y)
  2346. 1.756203682760182
  2347. >>> 0.25*np.pi*np.sqrt(y)
  2348. 1.7562036827601817
  2349. >>> elliprg(0, 0, z)
  2350. 1.224744871391589
  2351. >>> 0.5*np.sqrt(z)
  2352. 1.224744871391589
  2353. The surface area of a triaxial ellipsoid with semiaxes ``a``, ``b``, and
  2354. ``c`` is given by
  2355. .. math::
  2356. S = 4 \pi a b c R_{\mathrm{G}}(1 / a^2, 1 / b^2, 1 / c^2).
  2357. >>> def ellipsoid_area(a, b, c):
  2358. ... r = 4.0 * np.pi * a * b * c
  2359. ... return r * elliprg(1.0 / (a * a), 1.0 / (b * b), 1.0 / (c * c))
  2360. >>> print(ellipsoid_area(1, 3, 5))
  2361. 108.62688289491807
  2362. """)
  2363. add_newdoc(
  2364. "elliprj",
  2365. r"""
  2366. elliprj(x, y, z, p, out=None)
  2367. Symmetric elliptic integral of the third kind.
  2368. The function RJ is defined as [1]_
  2369. .. math::
  2370. R_{\mathrm{J}}(x, y, z, p) =
  2371. \frac{3}{2} \int_0^{+\infty} [(t + x) (t + y) (t + z)]^{-1/2}
  2372. (t + p)^{-1} dt
  2373. .. warning::
  2374. This function should be considered experimental when the inputs are
  2375. unbalanced. Check correctness with another independent implementation.
  2376. Parameters
  2377. ----------
  2378. x, y, z, p : array_like
  2379. Real or complex input parameters. `x`, `y`, or `z` are numbers in
  2380. the complex plane cut along the negative real axis (subject to further
  2381. constraints, see Notes), and at most one of them can be zero. `p` must
  2382. be non-zero.
  2383. out : ndarray, optional
  2384. Optional output array for the function values
  2385. Returns
  2386. -------
  2387. R : scalar or ndarray
  2388. Value of the integral. If all of `x`, `y`, `z`, and `p` are real, the
  2389. return value is real. Otherwise, the return value is complex.
  2390. If `p` is real and negative, while `x`, `y`, and `z` are real,
  2391. non-negative, and at most one of them is zero, the Cauchy principal
  2392. value is returned. [1]_ [2]_
  2393. Notes
  2394. -----
  2395. The code implements Carlson's algorithm based on the duplication theorems
  2396. and series expansion up to the 7th order. [3]_ The algorithm is slightly
  2397. different from its earlier incarnation as it appears in [1]_, in that the
  2398. call to `elliprc` (or ``atan``/``atanh``, see [4]_) is no longer needed in
  2399. the inner loop. Asymptotic approximations are used where arguments differ
  2400. widely in the order of magnitude. [5]_
  2401. The input values are subject to certain sufficient but not necessary
  2402. constaints when input arguments are complex. Notably, ``x``, ``y``, and
  2403. ``z`` must have non-negative real parts, unless two of them are
  2404. non-negative and complex-conjugates to each other while the other is a real
  2405. non-negative number. [1]_ If the inputs do not satisfy the sufficient
  2406. condition described in Ref. [1]_ they are rejected outright with the output
  2407. set to NaN.
  2408. In the case where one of ``x``, ``y``, and ``z`` is equal to ``p``, the
  2409. function ``elliprd`` should be preferred because of its less restrictive
  2410. domain.
  2411. .. versionadded:: 1.8.0
  2412. See Also
  2413. --------
  2414. elliprc : Degenerate symmetric integral.
  2415. elliprd : Symmetric elliptic integral of the second kind.
  2416. elliprf : Completely-symmetric elliptic integral of the first kind.
  2417. elliprg : Completely-symmetric elliptic integral of the second kind.
  2418. References
  2419. ----------
  2420. .. [1] B. C. Carlson, "Numerical computation of real or complex elliptic
  2421. integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
  2422. https://arxiv.org/abs/math/9409227
  2423. https://doi.org/10.1007/BF02198293
  2424. .. [2] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
  2425. Functions," NIST, US Dept. of Commerce.
  2426. https://dlmf.nist.gov/19.20.iii
  2427. .. [3] B. C. Carlson, J. FitzSimmons, "Reduction Theorems for Elliptic
  2428. Integrands with the Square Root of Two Quadratic Factors," J.
  2429. Comput. Appl. Math., vol. 118, nos. 1-2, pp. 71-85, 2000.
  2430. https://doi.org/10.1016/S0377-0427(00)00282-X
  2431. .. [4] F. Johansson, "Numerical Evaluation of Elliptic Functions, Elliptic
  2432. Integrals and Modular Forms," in J. Blumlein, C. Schneider, P.
  2433. Paule, eds., "Elliptic Integrals, Elliptic Functions and Modular
  2434. Forms in Quantum Field Theory," pp. 269-293, 2019 (Cham,
  2435. Switzerland: Springer Nature Switzerland)
  2436. https://arxiv.org/abs/1806.06725
  2437. https://doi.org/10.1007/978-3-030-04480-0
  2438. .. [5] B. C. Carlson, J. L. Gustafson, "Asymptotic Approximations for
  2439. Symmetric Elliptic Integrals," SIAM J. Math. Anls., vol. 25, no. 2,
  2440. pp. 288-303, 1994.
  2441. https://arxiv.org/abs/math/9310223
  2442. https://doi.org/10.1137/S0036141092228477
  2443. Examples
  2444. --------
  2445. Basic homogeneity property:
  2446. >>> import numpy as np
  2447. >>> from scipy.special import elliprj
  2448. >>> x = 1.2 + 3.4j
  2449. >>> y = 5.
  2450. >>> z = 6.
  2451. >>> p = 7.
  2452. >>> scale = 0.3 - 0.4j
  2453. >>> elliprj(scale*x, scale*y, scale*z, scale*p)
  2454. (0.10834905565679157+0.19694950747103812j)
  2455. >>> elliprj(x, y, z, p)*np.power(scale, -1.5)
  2456. (0.10834905565679556+0.19694950747103854j)
  2457. Reduction to simpler elliptic integral:
  2458. >>> elliprj(x, y, z, z)
  2459. (0.08288462362195129-0.028376809745123258j)
  2460. >>> from scipy.special import elliprd
  2461. >>> elliprd(x, y, z)
  2462. (0.08288462362195136-0.028376809745123296j)
  2463. All arguments coincide:
  2464. >>> elliprj(x, x, x, x)
  2465. (-0.03986825876151896-0.14051741840449586j)
  2466. >>> np.power(x, -1.5)
  2467. (-0.03986825876151894-0.14051741840449583j)
  2468. """)
  2469. add_newdoc("entr",
  2470. r"""
  2471. entr(x, out=None)
  2472. Elementwise function for computing entropy.
  2473. .. math:: \text{entr}(x) = \begin{cases} - x \log(x) & x > 0 \\ 0 & x = 0 \\ -\infty & \text{otherwise} \end{cases}
  2474. Parameters
  2475. ----------
  2476. x : ndarray
  2477. Input array.
  2478. out : ndarray, optional
  2479. Optional output array for the function values
  2480. Returns
  2481. -------
  2482. res : scalar or ndarray
  2483. The value of the elementwise entropy function at the given points `x`.
  2484. See Also
  2485. --------
  2486. kl_div, rel_entr, scipy.stats.entropy
  2487. Notes
  2488. -----
  2489. .. versionadded:: 0.15.0
  2490. This function is concave.
  2491. The origin of this function is in convex programming; see [1]_.
  2492. Given a probability distribution :math:`p_1, \ldots, p_n`,
  2493. the definition of entropy in the context of *information theory* is
  2494. .. math::
  2495. \sum_{i = 1}^n \mathrm{entr}(p_i).
  2496. To compute the latter quantity, use `scipy.stats.entropy`.
  2497. References
  2498. ----------
  2499. .. [1] Boyd, Stephen and Lieven Vandenberghe. *Convex optimization*.
  2500. Cambridge University Press, 2004.
  2501. :doi:`https://doi.org/10.1017/CBO9780511804441`
  2502. """)
  2503. add_newdoc("erf",
  2504. """
  2505. erf(z, out=None)
  2506. Returns the error function of complex argument.
  2507. It is defined as ``2/sqrt(pi)*integral(exp(-t**2), t=0..z)``.
  2508. Parameters
  2509. ----------
  2510. x : ndarray
  2511. Input array.
  2512. out : ndarray, optional
  2513. Optional output array for the function values
  2514. Returns
  2515. -------
  2516. res : scalar or ndarray
  2517. The values of the error function at the given points `x`.
  2518. See Also
  2519. --------
  2520. erfc, erfinv, erfcinv, wofz, erfcx, erfi
  2521. Notes
  2522. -----
  2523. The cumulative of the unit normal distribution is given by
  2524. ``Phi(z) = 1/2[1 + erf(z/sqrt(2))]``.
  2525. References
  2526. ----------
  2527. .. [1] https://en.wikipedia.org/wiki/Error_function
  2528. .. [2] Milton Abramowitz and Irene A. Stegun, eds.
  2529. Handbook of Mathematical Functions with Formulas,
  2530. Graphs, and Mathematical Tables. New York: Dover,
  2531. 1972. http://www.math.sfu.ca/~cbm/aands/page_297.htm
  2532. .. [3] Steven G. Johnson, Faddeeva W function implementation.
  2533. http://ab-initio.mit.edu/Faddeeva
  2534. Examples
  2535. --------
  2536. >>> import numpy as np
  2537. >>> from scipy import special
  2538. >>> import matplotlib.pyplot as plt
  2539. >>> x = np.linspace(-3, 3)
  2540. >>> plt.plot(x, special.erf(x))
  2541. >>> plt.xlabel('$x$')
  2542. >>> plt.ylabel('$erf(x)$')
  2543. >>> plt.show()
  2544. """)
  2545. add_newdoc("erfc",
  2546. """
  2547. erfc(x, out=None)
  2548. Complementary error function, ``1 - erf(x)``.
  2549. Parameters
  2550. ----------
  2551. x : array_like
  2552. Real or complex valued argument
  2553. out : ndarray, optional
  2554. Optional output array for the function results
  2555. Returns
  2556. -------
  2557. scalar or ndarray
  2558. Values of the complementary error function
  2559. See Also
  2560. --------
  2561. erf, erfi, erfcx, dawsn, wofz
  2562. References
  2563. ----------
  2564. .. [1] Steven G. Johnson, Faddeeva W function implementation.
  2565. http://ab-initio.mit.edu/Faddeeva
  2566. Examples
  2567. --------
  2568. >>> import numpy as np
  2569. >>> from scipy import special
  2570. >>> import matplotlib.pyplot as plt
  2571. >>> x = np.linspace(-3, 3)
  2572. >>> plt.plot(x, special.erfc(x))
  2573. >>> plt.xlabel('$x$')
  2574. >>> plt.ylabel('$erfc(x)$')
  2575. >>> plt.show()
  2576. """)
  2577. add_newdoc("erfi",
  2578. """
  2579. erfi(z, out=None)
  2580. Imaginary error function, ``-i erf(i z)``.
  2581. Parameters
  2582. ----------
  2583. z : array_like
  2584. Real or complex valued argument
  2585. out : ndarray, optional
  2586. Optional output array for the function results
  2587. Returns
  2588. -------
  2589. scalar or ndarray
  2590. Values of the imaginary error function
  2591. See Also
  2592. --------
  2593. erf, erfc, erfcx, dawsn, wofz
  2594. Notes
  2595. -----
  2596. .. versionadded:: 0.12.0
  2597. References
  2598. ----------
  2599. .. [1] Steven G. Johnson, Faddeeva W function implementation.
  2600. http://ab-initio.mit.edu/Faddeeva
  2601. Examples
  2602. --------
  2603. >>> import numpy as np
  2604. >>> from scipy import special
  2605. >>> import matplotlib.pyplot as plt
  2606. >>> x = np.linspace(-3, 3)
  2607. >>> plt.plot(x, special.erfi(x))
  2608. >>> plt.xlabel('$x$')
  2609. >>> plt.ylabel('$erfi(x)$')
  2610. >>> plt.show()
  2611. """)
  2612. add_newdoc("erfcx",
  2613. """
  2614. erfcx(x, out=None)
  2615. Scaled complementary error function, ``exp(x**2) * erfc(x)``.
  2616. Parameters
  2617. ----------
  2618. x : array_like
  2619. Real or complex valued argument
  2620. out : ndarray, optional
  2621. Optional output array for the function results
  2622. Returns
  2623. -------
  2624. scalar or ndarray
  2625. Values of the scaled complementary error function
  2626. See Also
  2627. --------
  2628. erf, erfc, erfi, dawsn, wofz
  2629. Notes
  2630. -----
  2631. .. versionadded:: 0.12.0
  2632. References
  2633. ----------
  2634. .. [1] Steven G. Johnson, Faddeeva W function implementation.
  2635. http://ab-initio.mit.edu/Faddeeva
  2636. Examples
  2637. --------
  2638. >>> import numpy as np
  2639. >>> from scipy import special
  2640. >>> import matplotlib.pyplot as plt
  2641. >>> x = np.linspace(-3, 3)
  2642. >>> plt.plot(x, special.erfcx(x))
  2643. >>> plt.xlabel('$x$')
  2644. >>> plt.ylabel('$erfcx(x)$')
  2645. >>> plt.show()
  2646. """)
  2647. add_newdoc(
  2648. "erfinv",
  2649. """
  2650. erfinv(y, out=None)
  2651. Inverse of the error function.
  2652. Computes the inverse of the error function.
  2653. In the complex domain, there is no unique complex number w satisfying
  2654. erf(w)=z. This indicates a true inverse function would be multivalued.
  2655. When the domain restricts to the real, -1 < x < 1, there is a unique real
  2656. number satisfying erf(erfinv(x)) = x.
  2657. Parameters
  2658. ----------
  2659. y : ndarray
  2660. Argument at which to evaluate. Domain: [-1, 1]
  2661. out : ndarray, optional
  2662. Optional output array for the function values
  2663. Returns
  2664. -------
  2665. erfinv : scalar or ndarray
  2666. The inverse of erf of y, element-wise
  2667. See Also
  2668. --------
  2669. erf : Error function of a complex argument
  2670. erfc : Complementary error function, ``1 - erf(x)``
  2671. erfcinv : Inverse of the complementary error function
  2672. Examples
  2673. --------
  2674. >>> import numpy as np
  2675. >>> import matplotlib.pyplot as plt
  2676. >>> from scipy.special import erfinv, erf
  2677. >>> erfinv(0.5)
  2678. 0.4769362762044699
  2679. >>> y = np.linspace(-1.0, 1.0, num=9)
  2680. >>> x = erfinv(y)
  2681. >>> x
  2682. array([ -inf, -0.81341985, -0.47693628, -0.22531206, 0. ,
  2683. 0.22531206, 0.47693628, 0.81341985, inf])
  2684. Verify that ``erf(erfinv(y))`` is ``y``.
  2685. >>> erf(x)
  2686. array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. ])
  2687. Plot the function:
  2688. >>> y = np.linspace(-1, 1, 200)
  2689. >>> fig, ax = plt.subplots()
  2690. >>> ax.plot(y, erfinv(y))
  2691. >>> ax.grid(True)
  2692. >>> ax.set_xlabel('y')
  2693. >>> ax.set_title('erfinv(y)')
  2694. >>> plt.show()
  2695. """)
  2696. add_newdoc(
  2697. "erfcinv",
  2698. """
  2699. erfcinv(y, out=None)
  2700. Inverse of the complementary error function.
  2701. Computes the inverse of the complementary error function.
  2702. In the complex domain, there is no unique complex number w satisfying
  2703. erfc(w)=z. This indicates a true inverse function would be multivalued.
  2704. When the domain restricts to the real, 0 < x < 2, there is a unique real
  2705. number satisfying erfc(erfcinv(x)) = erfcinv(erfc(x)).
  2706. It is related to inverse of the error function by erfcinv(1-x) = erfinv(x)
  2707. Parameters
  2708. ----------
  2709. y : ndarray
  2710. Argument at which to evaluate. Domain: [0, 2]
  2711. out : ndarray, optional
  2712. Optional output array for the function values
  2713. Returns
  2714. -------
  2715. erfcinv : scalar or ndarray
  2716. The inverse of erfc of y, element-wise
  2717. See Also
  2718. --------
  2719. erf : Error function of a complex argument
  2720. erfc : Complementary error function, ``1 - erf(x)``
  2721. erfinv : Inverse of the error function
  2722. Examples
  2723. --------
  2724. >>> import numpy as np
  2725. >>> import matplotlib.pyplot as plt
  2726. >>> from scipy.special import erfcinv
  2727. >>> erfcinv(0.5)
  2728. 0.4769362762044699
  2729. >>> y = np.linspace(0.0, 2.0, num=11)
  2730. >>> erfcinv(y)
  2731. array([ inf, 0.9061938 , 0.59511608, 0.37080716, 0.17914345,
  2732. -0. , -0.17914345, -0.37080716, -0.59511608, -0.9061938 ,
  2733. -inf])
  2734. Plot the function:
  2735. >>> y = np.linspace(0, 2, 200)
  2736. >>> fig, ax = plt.subplots()
  2737. >>> ax.plot(y, erfcinv(y))
  2738. >>> ax.grid(True)
  2739. >>> ax.set_xlabel('y')
  2740. >>> ax.set_title('erfcinv(y)')
  2741. >>> plt.show()
  2742. """)
  2743. add_newdoc("eval_jacobi",
  2744. r"""
  2745. eval_jacobi(n, alpha, beta, x, out=None)
  2746. Evaluate Jacobi polynomial at a point.
  2747. The Jacobi polynomials can be defined via the Gauss hypergeometric
  2748. function :math:`{}_2F_1` as
  2749. .. math::
  2750. P_n^{(\alpha, \beta)}(x) = \frac{(\alpha + 1)_n}{\Gamma(n + 1)}
  2751. {}_2F_1(-n, 1 + \alpha + \beta + n; \alpha + 1; (1 - z)/2)
  2752. where :math:`(\cdot)_n` is the Pochhammer symbol; see `poch`. When
  2753. :math:`n` is an integer the result is a polynomial of degree
  2754. :math:`n`. See 22.5.42 in [AS]_ for details.
  2755. Parameters
  2756. ----------
  2757. n : array_like
  2758. Degree of the polynomial. If not an integer the result is
  2759. determined via the relation to the Gauss hypergeometric
  2760. function.
  2761. alpha : array_like
  2762. Parameter
  2763. beta : array_like
  2764. Parameter
  2765. x : array_like
  2766. Points at which to evaluate the polynomial
  2767. out : ndarray, optional
  2768. Optional output array for the function values
  2769. Returns
  2770. -------
  2771. P : scalar or ndarray
  2772. Values of the Jacobi polynomial
  2773. See Also
  2774. --------
  2775. roots_jacobi : roots and quadrature weights of Jacobi polynomials
  2776. jacobi : Jacobi polynomial object
  2777. hyp2f1 : Gauss hypergeometric function
  2778. References
  2779. ----------
  2780. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2781. Handbook of Mathematical Functions with Formulas,
  2782. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2783. """)
  2784. add_newdoc("eval_sh_jacobi",
  2785. r"""
  2786. eval_sh_jacobi(n, p, q, x, out=None)
  2787. Evaluate shifted Jacobi polynomial at a point.
  2788. Defined by
  2789. .. math::
  2790. G_n^{(p, q)}(x)
  2791. = \binom{2n + p - 1}{n}^{-1} P_n^{(p - q, q - 1)}(2x - 1),
  2792. where :math:`P_n^{(\cdot, \cdot)}` is the n-th Jacobi
  2793. polynomial. See 22.5.2 in [AS]_ for details.
  2794. Parameters
  2795. ----------
  2796. n : int
  2797. Degree of the polynomial. If not an integer, the result is
  2798. determined via the relation to `binom` and `eval_jacobi`.
  2799. p : float
  2800. Parameter
  2801. q : float
  2802. Parameter
  2803. out : ndarray, optional
  2804. Optional output array for the function values
  2805. Returns
  2806. -------
  2807. G : scalar or ndarray
  2808. Values of the shifted Jacobi polynomial.
  2809. See Also
  2810. --------
  2811. roots_sh_jacobi : roots and quadrature weights of shifted Jacobi
  2812. polynomials
  2813. sh_jacobi : shifted Jacobi polynomial object
  2814. eval_jacobi : evaluate Jacobi polynomials
  2815. References
  2816. ----------
  2817. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2818. Handbook of Mathematical Functions with Formulas,
  2819. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2820. """)
  2821. add_newdoc("eval_gegenbauer",
  2822. r"""
  2823. eval_gegenbauer(n, alpha, x, out=None)
  2824. Evaluate Gegenbauer polynomial at a point.
  2825. The Gegenbauer polynomials can be defined via the Gauss
  2826. hypergeometric function :math:`{}_2F_1` as
  2827. .. math::
  2828. C_n^{(\alpha)} = \frac{(2\alpha)_n}{\Gamma(n + 1)}
  2829. {}_2F_1(-n, 2\alpha + n; \alpha + 1/2; (1 - z)/2).
  2830. When :math:`n` is an integer the result is a polynomial of degree
  2831. :math:`n`. See 22.5.46 in [AS]_ for details.
  2832. Parameters
  2833. ----------
  2834. n : array_like
  2835. Degree of the polynomial. If not an integer, the result is
  2836. determined via the relation to the Gauss hypergeometric
  2837. function.
  2838. alpha : array_like
  2839. Parameter
  2840. x : array_like
  2841. Points at which to evaluate the Gegenbauer polynomial
  2842. out : ndarray, optional
  2843. Optional output array for the function values
  2844. Returns
  2845. -------
  2846. C : scalar or ndarray
  2847. Values of the Gegenbauer polynomial
  2848. See Also
  2849. --------
  2850. roots_gegenbauer : roots and quadrature weights of Gegenbauer
  2851. polynomials
  2852. gegenbauer : Gegenbauer polynomial object
  2853. hyp2f1 : Gauss hypergeometric function
  2854. References
  2855. ----------
  2856. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2857. Handbook of Mathematical Functions with Formulas,
  2858. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2859. """)
  2860. add_newdoc("eval_chebyt",
  2861. r"""
  2862. eval_chebyt(n, x, out=None)
  2863. Evaluate Chebyshev polynomial of the first kind at a point.
  2864. The Chebyshev polynomials of the first kind can be defined via the
  2865. Gauss hypergeometric function :math:`{}_2F_1` as
  2866. .. math::
  2867. T_n(x) = {}_2F_1(n, -n; 1/2; (1 - x)/2).
  2868. When :math:`n` is an integer the result is a polynomial of degree
  2869. :math:`n`. See 22.5.47 in [AS]_ for details.
  2870. Parameters
  2871. ----------
  2872. n : array_like
  2873. Degree of the polynomial. If not an integer, the result is
  2874. determined via the relation to the Gauss hypergeometric
  2875. function.
  2876. x : array_like
  2877. Points at which to evaluate the Chebyshev polynomial
  2878. out : ndarray, optional
  2879. Optional output array for the function values
  2880. Returns
  2881. -------
  2882. T : scalar or ndarray
  2883. Values of the Chebyshev polynomial
  2884. See Also
  2885. --------
  2886. roots_chebyt : roots and quadrature weights of Chebyshev
  2887. polynomials of the first kind
  2888. chebyu : Chebychev polynomial object
  2889. eval_chebyu : evaluate Chebyshev polynomials of the second kind
  2890. hyp2f1 : Gauss hypergeometric function
  2891. numpy.polynomial.chebyshev.Chebyshev : Chebyshev series
  2892. Notes
  2893. -----
  2894. This routine is numerically stable for `x` in ``[-1, 1]`` at least
  2895. up to order ``10000``.
  2896. References
  2897. ----------
  2898. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2899. Handbook of Mathematical Functions with Formulas,
  2900. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2901. """)
  2902. add_newdoc("eval_chebyu",
  2903. r"""
  2904. eval_chebyu(n, x, out=None)
  2905. Evaluate Chebyshev polynomial of the second kind at a point.
  2906. The Chebyshev polynomials of the second kind can be defined via
  2907. the Gauss hypergeometric function :math:`{}_2F_1` as
  2908. .. math::
  2909. U_n(x) = (n + 1) {}_2F_1(-n, n + 2; 3/2; (1 - x)/2).
  2910. When :math:`n` is an integer the result is a polynomial of degree
  2911. :math:`n`. See 22.5.48 in [AS]_ for details.
  2912. Parameters
  2913. ----------
  2914. n : array_like
  2915. Degree of the polynomial. If not an integer, the result is
  2916. determined via the relation to the Gauss hypergeometric
  2917. function.
  2918. x : array_like
  2919. Points at which to evaluate the Chebyshev polynomial
  2920. out : ndarray, optional
  2921. Optional output array for the function values
  2922. Returns
  2923. -------
  2924. U : scalar or ndarray
  2925. Values of the Chebyshev polynomial
  2926. See Also
  2927. --------
  2928. roots_chebyu : roots and quadrature weights of Chebyshev
  2929. polynomials of the second kind
  2930. chebyu : Chebyshev polynomial object
  2931. eval_chebyt : evaluate Chebyshev polynomials of the first kind
  2932. hyp2f1 : Gauss hypergeometric function
  2933. References
  2934. ----------
  2935. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2936. Handbook of Mathematical Functions with Formulas,
  2937. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2938. """)
  2939. add_newdoc("eval_chebys",
  2940. r"""
  2941. eval_chebys(n, x, out=None)
  2942. Evaluate Chebyshev polynomial of the second kind on [-2, 2] at a
  2943. point.
  2944. These polynomials are defined as
  2945. .. math::
  2946. S_n(x) = U_n(x/2)
  2947. where :math:`U_n` is a Chebyshev polynomial of the second
  2948. kind. See 22.5.13 in [AS]_ for details.
  2949. Parameters
  2950. ----------
  2951. n : array_like
  2952. Degree of the polynomial. If not an integer, the result is
  2953. determined via the relation to `eval_chebyu`.
  2954. x : array_like
  2955. Points at which to evaluate the Chebyshev polynomial
  2956. out : ndarray, optional
  2957. Optional output array for the function values
  2958. Returns
  2959. -------
  2960. S : scalar or ndarray
  2961. Values of the Chebyshev polynomial
  2962. See Also
  2963. --------
  2964. roots_chebys : roots and quadrature weights of Chebyshev
  2965. polynomials of the second kind on [-2, 2]
  2966. chebys : Chebyshev polynomial object
  2967. eval_chebyu : evaluate Chebyshev polynomials of the second kind
  2968. References
  2969. ----------
  2970. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2971. Handbook of Mathematical Functions with Formulas,
  2972. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2973. Examples
  2974. --------
  2975. >>> import numpy as np
  2976. >>> import scipy.special as sc
  2977. They are a scaled version of the Chebyshev polynomials of the
  2978. second kind.
  2979. >>> x = np.linspace(-2, 2, 6)
  2980. >>> sc.eval_chebys(3, x)
  2981. array([-4. , 0.672, 0.736, -0.736, -0.672, 4. ])
  2982. >>> sc.eval_chebyu(3, x / 2)
  2983. array([-4. , 0.672, 0.736, -0.736, -0.672, 4. ])
  2984. """)
  2985. add_newdoc("eval_chebyc",
  2986. r"""
  2987. eval_chebyc(n, x, out=None)
  2988. Evaluate Chebyshev polynomial of the first kind on [-2, 2] at a
  2989. point.
  2990. These polynomials are defined as
  2991. .. math::
  2992. C_n(x) = 2 T_n(x/2)
  2993. where :math:`T_n` is a Chebyshev polynomial of the first kind. See
  2994. 22.5.11 in [AS]_ for details.
  2995. Parameters
  2996. ----------
  2997. n : array_like
  2998. Degree of the polynomial. If not an integer, the result is
  2999. determined via the relation to `eval_chebyt`.
  3000. x : array_like
  3001. Points at which to evaluate the Chebyshev polynomial
  3002. out : ndarray, optional
  3003. Optional output array for the function values
  3004. Returns
  3005. -------
  3006. C : scalar or ndarray
  3007. Values of the Chebyshev polynomial
  3008. See Also
  3009. --------
  3010. roots_chebyc : roots and quadrature weights of Chebyshev
  3011. polynomials of the first kind on [-2, 2]
  3012. chebyc : Chebyshev polynomial object
  3013. numpy.polynomial.chebyshev.Chebyshev : Chebyshev series
  3014. eval_chebyt : evaluate Chebycshev polynomials of the first kind
  3015. References
  3016. ----------
  3017. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  3018. Handbook of Mathematical Functions with Formulas,
  3019. Graphs, and Mathematical Tables. New York: Dover, 1972.
  3020. Examples
  3021. --------
  3022. >>> import numpy as np
  3023. >>> import scipy.special as sc
  3024. They are a scaled version of the Chebyshev polynomials of the
  3025. first kind.
  3026. >>> x = np.linspace(-2, 2, 6)
  3027. >>> sc.eval_chebyc(3, x)
  3028. array([-2. , 1.872, 1.136, -1.136, -1.872, 2. ])
  3029. >>> 2 * sc.eval_chebyt(3, x / 2)
  3030. array([-2. , 1.872, 1.136, -1.136, -1.872, 2. ])
  3031. """)
  3032. add_newdoc("eval_sh_chebyt",
  3033. r"""
  3034. eval_sh_chebyt(n, x, out=None)
  3035. Evaluate shifted Chebyshev polynomial of the first kind at a
  3036. point.
  3037. These polynomials are defined as
  3038. .. math::
  3039. T_n^*(x) = T_n(2x - 1)
  3040. where :math:`T_n` is a Chebyshev polynomial of the first kind. See
  3041. 22.5.14 in [AS]_ for details.
  3042. Parameters
  3043. ----------
  3044. n : array_like
  3045. Degree of the polynomial. If not an integer, the result is
  3046. determined via the relation to `eval_chebyt`.
  3047. x : array_like
  3048. Points at which to evaluate the shifted Chebyshev polynomial
  3049. out : ndarray, optional
  3050. Optional output array for the function values
  3051. Returns
  3052. -------
  3053. T : scalar or ndarray
  3054. Values of the shifted Chebyshev polynomial
  3055. See Also
  3056. --------
  3057. roots_sh_chebyt : roots and quadrature weights of shifted
  3058. Chebyshev polynomials of the first kind
  3059. sh_chebyt : shifted Chebyshev polynomial object
  3060. eval_chebyt : evaluate Chebyshev polynomials of the first kind
  3061. numpy.polynomial.chebyshev.Chebyshev : Chebyshev series
  3062. References
  3063. ----------
  3064. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  3065. Handbook of Mathematical Functions with Formulas,
  3066. Graphs, and Mathematical Tables. New York: Dover, 1972.
  3067. """)
  3068. add_newdoc("eval_sh_chebyu",
  3069. r"""
  3070. eval_sh_chebyu(n, x, out=None)
  3071. Evaluate shifted Chebyshev polynomial of the second kind at a
  3072. point.
  3073. These polynomials are defined as
  3074. .. math::
  3075. U_n^*(x) = U_n(2x - 1)
  3076. where :math:`U_n` is a Chebyshev polynomial of the first kind. See
  3077. 22.5.15 in [AS]_ for details.
  3078. Parameters
  3079. ----------
  3080. n : array_like
  3081. Degree of the polynomial. If not an integer, the result is
  3082. determined via the relation to `eval_chebyu`.
  3083. x : array_like
  3084. Points at which to evaluate the shifted Chebyshev polynomial
  3085. out : ndarray, optional
  3086. Optional output array for the function values
  3087. Returns
  3088. -------
  3089. U : scalar or ndarray
  3090. Values of the shifted Chebyshev polynomial
  3091. See Also
  3092. --------
  3093. roots_sh_chebyu : roots and quadrature weights of shifted
  3094. Chebychev polynomials of the second kind
  3095. sh_chebyu : shifted Chebyshev polynomial object
  3096. eval_chebyu : evaluate Chebyshev polynomials of the second kind
  3097. References
  3098. ----------
  3099. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  3100. Handbook of Mathematical Functions with Formulas,
  3101. Graphs, and Mathematical Tables. New York: Dover, 1972.
  3102. """)
  3103. add_newdoc("eval_legendre",
  3104. r"""
  3105. eval_legendre(n, x, out=None)
  3106. Evaluate Legendre polynomial at a point.
  3107. The Legendre polynomials can be defined via the Gauss
  3108. hypergeometric function :math:`{}_2F_1` as
  3109. .. math::
  3110. P_n(x) = {}_2F_1(-n, n + 1; 1; (1 - x)/2).
  3111. When :math:`n` is an integer the result is a polynomial of degree
  3112. :math:`n`. See 22.5.49 in [AS]_ for details.
  3113. Parameters
  3114. ----------
  3115. n : array_like
  3116. Degree of the polynomial. If not an integer, the result is
  3117. determined via the relation to the Gauss hypergeometric
  3118. function.
  3119. x : array_like
  3120. Points at which to evaluate the Legendre polynomial
  3121. out : ndarray, optional
  3122. Optional output array for the function values
  3123. Returns
  3124. -------
  3125. P : scalar or ndarray
  3126. Values of the Legendre polynomial
  3127. See Also
  3128. --------
  3129. roots_legendre : roots and quadrature weights of Legendre
  3130. polynomials
  3131. legendre : Legendre polynomial object
  3132. hyp2f1 : Gauss hypergeometric function
  3133. numpy.polynomial.legendre.Legendre : Legendre series
  3134. References
  3135. ----------
  3136. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  3137. Handbook of Mathematical Functions with Formulas,
  3138. Graphs, and Mathematical Tables. New York: Dover, 1972.
  3139. Examples
  3140. --------
  3141. >>> import numpy as np
  3142. >>> from scipy.special import eval_legendre
  3143. Evaluate the zero-order Legendre polynomial at x = 0
  3144. >>> eval_legendre(0, 0)
  3145. 1.0
  3146. Evaluate the first-order Legendre polynomial between -1 and 1
  3147. >>> X = np.linspace(-1, 1, 5) # Domain of Legendre polynomials
  3148. >>> eval_legendre(1, X)
  3149. array([-1. , -0.5, 0. , 0.5, 1. ])
  3150. Evaluate Legendre polynomials of order 0 through 4 at x = 0
  3151. >>> N = range(0, 5)
  3152. >>> eval_legendre(N, 0)
  3153. array([ 1. , 0. , -0.5 , 0. , 0.375])
  3154. Plot Legendre polynomials of order 0 through 4
  3155. >>> X = np.linspace(-1, 1)
  3156. >>> import matplotlib.pyplot as plt
  3157. >>> for n in range(0, 5):
  3158. ... y = eval_legendre(n, X)
  3159. ... plt.plot(X, y, label=r'$P_{}(x)$'.format(n))
  3160. >>> plt.title("Legendre Polynomials")
  3161. >>> plt.xlabel("x")
  3162. >>> plt.ylabel(r'$P_n(x)$')
  3163. >>> plt.legend(loc='lower right')
  3164. >>> plt.show()
  3165. """)
  3166. add_newdoc("eval_sh_legendre",
  3167. r"""
  3168. eval_sh_legendre(n, x, out=None)
  3169. Evaluate shifted Legendre polynomial at a point.
  3170. These polynomials are defined as
  3171. .. math::
  3172. P_n^*(x) = P_n(2x - 1)
  3173. where :math:`P_n` is a Legendre polynomial. See 2.2.11 in [AS]_
  3174. for details.
  3175. Parameters
  3176. ----------
  3177. n : array_like
  3178. Degree of the polynomial. If not an integer, the value is
  3179. determined via the relation to `eval_legendre`.
  3180. x : array_like
  3181. Points at which to evaluate the shifted Legendre polynomial
  3182. out : ndarray, optional
  3183. Optional output array for the function values
  3184. Returns
  3185. -------
  3186. P : scalar or ndarray
  3187. Values of the shifted Legendre polynomial
  3188. See Also
  3189. --------
  3190. roots_sh_legendre : roots and quadrature weights of shifted
  3191. Legendre polynomials
  3192. sh_legendre : shifted Legendre polynomial object
  3193. eval_legendre : evaluate Legendre polynomials
  3194. numpy.polynomial.legendre.Legendre : Legendre series
  3195. References
  3196. ----------
  3197. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  3198. Handbook of Mathematical Functions with Formulas,
  3199. Graphs, and Mathematical Tables. New York: Dover, 1972.
  3200. """)
  3201. add_newdoc("eval_genlaguerre",
  3202. r"""
  3203. eval_genlaguerre(n, alpha, x, out=None)
  3204. Evaluate generalized Laguerre polynomial at a point.
  3205. The generalized Laguerre polynomials can be defined via the
  3206. confluent hypergeometric function :math:`{}_1F_1` as
  3207. .. math::
  3208. L_n^{(\alpha)}(x) = \binom{n + \alpha}{n}
  3209. {}_1F_1(-n, \alpha + 1, x).
  3210. When :math:`n` is an integer the result is a polynomial of degree
  3211. :math:`n`. See 22.5.54 in [AS]_ for details. The Laguerre
  3212. polynomials are the special case where :math:`\alpha = 0`.
  3213. Parameters
  3214. ----------
  3215. n : array_like
  3216. Degree of the polynomial. If not an integer, the result is
  3217. determined via the relation to the confluent hypergeometric
  3218. function.
  3219. alpha : array_like
  3220. Parameter; must have ``alpha > -1``
  3221. x : array_like
  3222. Points at which to evaluate the generalized Laguerre
  3223. polynomial
  3224. out : ndarray, optional
  3225. Optional output array for the function values
  3226. Returns
  3227. -------
  3228. L : scalar or ndarray
  3229. Values of the generalized Laguerre polynomial
  3230. See Also
  3231. --------
  3232. roots_genlaguerre : roots and quadrature weights of generalized
  3233. Laguerre polynomials
  3234. genlaguerre : generalized Laguerre polynomial object
  3235. hyp1f1 : confluent hypergeometric function
  3236. eval_laguerre : evaluate Laguerre polynomials
  3237. References
  3238. ----------
  3239. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  3240. Handbook of Mathematical Functions with Formulas,
  3241. Graphs, and Mathematical Tables. New York: Dover, 1972.
  3242. """)
  3243. add_newdoc("eval_laguerre",
  3244. r"""
  3245. eval_laguerre(n, x, out=None)
  3246. Evaluate Laguerre polynomial at a point.
  3247. The Laguerre polynomials can be defined via the confluent
  3248. hypergeometric function :math:`{}_1F_1` as
  3249. .. math::
  3250. L_n(x) = {}_1F_1(-n, 1, x).
  3251. See 22.5.16 and 22.5.54 in [AS]_ for details. When :math:`n` is an
  3252. integer the result is a polynomial of degree :math:`n`.
  3253. Parameters
  3254. ----------
  3255. n : array_like
  3256. Degree of the polynomial. If not an integer the result is
  3257. determined via the relation to the confluent hypergeometric
  3258. function.
  3259. x : array_like
  3260. Points at which to evaluate the Laguerre polynomial
  3261. out : ndarray, optional
  3262. Optional output array for the function values
  3263. Returns
  3264. -------
  3265. L : scalar or ndarray
  3266. Values of the Laguerre polynomial
  3267. See Also
  3268. --------
  3269. roots_laguerre : roots and quadrature weights of Laguerre
  3270. polynomials
  3271. laguerre : Laguerre polynomial object
  3272. numpy.polynomial.laguerre.Laguerre : Laguerre series
  3273. eval_genlaguerre : evaluate generalized Laguerre polynomials
  3274. References
  3275. ----------
  3276. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  3277. Handbook of Mathematical Functions with Formulas,
  3278. Graphs, and Mathematical Tables. New York: Dover, 1972.
  3279. """)
  3280. add_newdoc("eval_hermite",
  3281. r"""
  3282. eval_hermite(n, x, out=None)
  3283. Evaluate physicist's Hermite polynomial at a point.
  3284. Defined by
  3285. .. math::
  3286. H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2};
  3287. :math:`H_n` is a polynomial of degree :math:`n`. See 22.11.7 in
  3288. [AS]_ for details.
  3289. Parameters
  3290. ----------
  3291. n : array_like
  3292. Degree of the polynomial
  3293. x : array_like
  3294. Points at which to evaluate the Hermite polynomial
  3295. out : ndarray, optional
  3296. Optional output array for the function values
  3297. Returns
  3298. -------
  3299. H : scalar or ndarray
  3300. Values of the Hermite polynomial
  3301. See Also
  3302. --------
  3303. roots_hermite : roots and quadrature weights of physicist's
  3304. Hermite polynomials
  3305. hermite : physicist's Hermite polynomial object
  3306. numpy.polynomial.hermite.Hermite : Physicist's Hermite series
  3307. eval_hermitenorm : evaluate Probabilist's Hermite polynomials
  3308. References
  3309. ----------
  3310. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  3311. Handbook of Mathematical Functions with Formulas,
  3312. Graphs, and Mathematical Tables. New York: Dover, 1972.
  3313. """)
  3314. add_newdoc("eval_hermitenorm",
  3315. r"""
  3316. eval_hermitenorm(n, x, out=None)
  3317. Evaluate probabilist's (normalized) Hermite polynomial at a
  3318. point.
  3319. Defined by
  3320. .. math::
  3321. He_n(x) = (-1)^n e^{x^2/2} \frac{d^n}{dx^n} e^{-x^2/2};
  3322. :math:`He_n` is a polynomial of degree :math:`n`. See 22.11.8 in
  3323. [AS]_ for details.
  3324. Parameters
  3325. ----------
  3326. n : array_like
  3327. Degree of the polynomial
  3328. x : array_like
  3329. Points at which to evaluate the Hermite polynomial
  3330. out : ndarray, optional
  3331. Optional output array for the function values
  3332. Returns
  3333. -------
  3334. He : scalar or ndarray
  3335. Values of the Hermite polynomial
  3336. See Also
  3337. --------
  3338. roots_hermitenorm : roots and quadrature weights of probabilist's
  3339. Hermite polynomials
  3340. hermitenorm : probabilist's Hermite polynomial object
  3341. numpy.polynomial.hermite_e.HermiteE : Probabilist's Hermite series
  3342. eval_hermite : evaluate physicist's Hermite polynomials
  3343. References
  3344. ----------
  3345. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  3346. Handbook of Mathematical Functions with Formulas,
  3347. Graphs, and Mathematical Tables. New York: Dover, 1972.
  3348. """)
  3349. add_newdoc("exp1",
  3350. r"""
  3351. exp1(z, out=None)
  3352. Exponential integral E1.
  3353. For complex :math:`z \ne 0` the exponential integral can be defined as
  3354. [1]_
  3355. .. math::
  3356. E_1(z) = \int_z^\infty \frac{e^{-t}}{t} dt,
  3357. where the path of the integral does not cross the negative real
  3358. axis or pass through the origin.
  3359. Parameters
  3360. ----------
  3361. z: array_like
  3362. Real or complex argument.
  3363. out : ndarray, optional
  3364. Optional output array for the function results
  3365. Returns
  3366. -------
  3367. scalar or ndarray
  3368. Values of the exponential integral E1
  3369. See Also
  3370. --------
  3371. expi : exponential integral :math:`Ei`
  3372. expn : generalization of :math:`E_1`
  3373. Notes
  3374. -----
  3375. For :math:`x > 0` it is related to the exponential integral
  3376. :math:`Ei` (see `expi`) via the relation
  3377. .. math::
  3378. E_1(x) = -Ei(-x).
  3379. References
  3380. ----------
  3381. .. [1] Digital Library of Mathematical Functions, 6.2.1
  3382. https://dlmf.nist.gov/6.2#E1
  3383. Examples
  3384. --------
  3385. >>> import numpy as np
  3386. >>> import scipy.special as sc
  3387. It has a pole at 0.
  3388. >>> sc.exp1(0)
  3389. inf
  3390. It has a branch cut on the negative real axis.
  3391. >>> sc.exp1(-1)
  3392. nan
  3393. >>> sc.exp1(complex(-1, 0))
  3394. (-1.8951178163559368-3.141592653589793j)
  3395. >>> sc.exp1(complex(-1, -0.0))
  3396. (-1.8951178163559368+3.141592653589793j)
  3397. It approaches 0 along the positive real axis.
  3398. >>> sc.exp1([1, 10, 100, 1000])
  3399. array([2.19383934e-01, 4.15696893e-06, 3.68359776e-46, 0.00000000e+00])
  3400. It is related to `expi`.
  3401. >>> x = np.array([1, 2, 3, 4])
  3402. >>> sc.exp1(x)
  3403. array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
  3404. >>> -sc.expi(-x)
  3405. array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
  3406. """)
  3407. add_newdoc("exp10",
  3408. """
  3409. exp10(x, out=None)
  3410. Compute ``10**x`` element-wise.
  3411. Parameters
  3412. ----------
  3413. x : array_like
  3414. `x` must contain real numbers.
  3415. out : ndarray, optional
  3416. Optional output array for the function values
  3417. Returns
  3418. -------
  3419. scalar or ndarray
  3420. ``10**x``, computed element-wise.
  3421. Examples
  3422. --------
  3423. >>> import numpy as np
  3424. >>> from scipy.special import exp10
  3425. >>> exp10(3)
  3426. 1000.0
  3427. >>> x = np.array([[-1, -0.5, 0], [0.5, 1, 1.5]])
  3428. >>> exp10(x)
  3429. array([[ 0.1 , 0.31622777, 1. ],
  3430. [ 3.16227766, 10. , 31.6227766 ]])
  3431. """)
  3432. add_newdoc("exp2",
  3433. """
  3434. exp2(x, out=None)
  3435. Compute ``2**x`` element-wise.
  3436. Parameters
  3437. ----------
  3438. x : array_like
  3439. `x` must contain real numbers.
  3440. out : ndarray, optional
  3441. Optional output array for the function values
  3442. Returns
  3443. -------
  3444. scalar or ndarray
  3445. ``2**x``, computed element-wise.
  3446. Examples
  3447. --------
  3448. >>> import numpy as np
  3449. >>> from scipy.special import exp2
  3450. >>> exp2(3)
  3451. 8.0
  3452. >>> x = np.array([[-1, -0.5, 0], [0.5, 1, 1.5]])
  3453. >>> exp2(x)
  3454. array([[ 0.5 , 0.70710678, 1. ],
  3455. [ 1.41421356, 2. , 2.82842712]])
  3456. """)
  3457. add_newdoc("expi",
  3458. r"""
  3459. expi(x, out=None)
  3460. Exponential integral Ei.
  3461. For real :math:`x`, the exponential integral is defined as [1]_
  3462. .. math::
  3463. Ei(x) = \int_{-\infty}^x \frac{e^t}{t} dt.
  3464. For :math:`x > 0` the integral is understood as a Cauchy principal
  3465. value.
  3466. It is extended to the complex plane by analytic continuation of
  3467. the function on the interval :math:`(0, \infty)`. The complex
  3468. variant has a branch cut on the negative real axis.
  3469. Parameters
  3470. ----------
  3471. x : array_like
  3472. Real or complex valued argument
  3473. out : ndarray, optional
  3474. Optional output array for the function results
  3475. Returns
  3476. -------
  3477. scalar or ndarray
  3478. Values of the exponential integral
  3479. Notes
  3480. -----
  3481. The exponential integrals :math:`E_1` and :math:`Ei` satisfy the
  3482. relation
  3483. .. math::
  3484. E_1(x) = -Ei(-x)
  3485. for :math:`x > 0`.
  3486. See Also
  3487. --------
  3488. exp1 : Exponential integral :math:`E_1`
  3489. expn : Generalized exponential integral :math:`E_n`
  3490. References
  3491. ----------
  3492. .. [1] Digital Library of Mathematical Functions, 6.2.5
  3493. https://dlmf.nist.gov/6.2#E5
  3494. Examples
  3495. --------
  3496. >>> import numpy as np
  3497. >>> import scipy.special as sc
  3498. It is related to `exp1`.
  3499. >>> x = np.array([1, 2, 3, 4])
  3500. >>> -sc.expi(-x)
  3501. array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
  3502. >>> sc.exp1(x)
  3503. array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
  3504. The complex variant has a branch cut on the negative real axis.
  3505. >>> sc.expi(-1 + 1e-12j)
  3506. (-0.21938393439552062+3.1415926535894254j)
  3507. >>> sc.expi(-1 - 1e-12j)
  3508. (-0.21938393439552062-3.1415926535894254j)
  3509. As the complex variant approaches the branch cut, the real parts
  3510. approach the value of the real variant.
  3511. >>> sc.expi(-1)
  3512. -0.21938393439552062
  3513. The SciPy implementation returns the real variant for complex
  3514. values on the branch cut.
  3515. >>> sc.expi(complex(-1, 0.0))
  3516. (-0.21938393439552062-0j)
  3517. >>> sc.expi(complex(-1, -0.0))
  3518. (-0.21938393439552062-0j)
  3519. """)
  3520. add_newdoc('expit',
  3521. """
  3522. expit(x, out=None)
  3523. Expit (a.k.a. logistic sigmoid) ufunc for ndarrays.
  3524. The expit function, also known as the logistic sigmoid function, is
  3525. defined as ``expit(x) = 1/(1+exp(-x))``. It is the inverse of the
  3526. logit function.
  3527. Parameters
  3528. ----------
  3529. x : ndarray
  3530. The ndarray to apply expit to element-wise.
  3531. out : ndarray, optional
  3532. Optional output array for the function values
  3533. Returns
  3534. -------
  3535. scalar or ndarray
  3536. An ndarray of the same shape as x. Its entries
  3537. are `expit` of the corresponding entry of x.
  3538. See Also
  3539. --------
  3540. logit
  3541. Notes
  3542. -----
  3543. As a ufunc expit takes a number of optional
  3544. keyword arguments. For more information
  3545. see `ufuncs <https://docs.scipy.org/doc/numpy/reference/ufuncs.html>`_
  3546. .. versionadded:: 0.10.0
  3547. Examples
  3548. --------
  3549. >>> import numpy as np
  3550. >>> from scipy.special import expit, logit
  3551. >>> expit([-np.inf, -1.5, 0, 1.5, np.inf])
  3552. array([ 0. , 0.18242552, 0.5 , 0.81757448, 1. ])
  3553. `logit` is the inverse of `expit`:
  3554. >>> logit(expit([-2.5, 0, 3.1, 5.0]))
  3555. array([-2.5, 0. , 3.1, 5. ])
  3556. Plot expit(x) for x in [-6, 6]:
  3557. >>> import matplotlib.pyplot as plt
  3558. >>> x = np.linspace(-6, 6, 121)
  3559. >>> y = expit(x)
  3560. >>> plt.plot(x, y)
  3561. >>> plt.grid()
  3562. >>> plt.xlim(-6, 6)
  3563. >>> plt.xlabel('x')
  3564. >>> plt.title('expit(x)')
  3565. >>> plt.show()
  3566. """)
  3567. add_newdoc("expm1",
  3568. """
  3569. expm1(x, out=None)
  3570. Compute ``exp(x) - 1``.
  3571. When `x` is near zero, ``exp(x)`` is near 1, so the numerical calculation
  3572. of ``exp(x) - 1`` can suffer from catastrophic loss of precision.
  3573. ``expm1(x)`` is implemented to avoid the loss of precision that occurs when
  3574. `x` is near zero.
  3575. Parameters
  3576. ----------
  3577. x : array_like
  3578. `x` must contain real numbers.
  3579. out : ndarray, optional
  3580. Optional output array for the function values
  3581. Returns
  3582. -------
  3583. scalar or ndarray
  3584. ``exp(x) - 1`` computed element-wise.
  3585. Examples
  3586. --------
  3587. >>> import numpy as np
  3588. >>> from scipy.special import expm1
  3589. >>> expm1(1.0)
  3590. 1.7182818284590451
  3591. >>> expm1([-0.2, -0.1, 0, 0.1, 0.2])
  3592. array([-0.18126925, -0.09516258, 0. , 0.10517092, 0.22140276])
  3593. The exact value of ``exp(7.5e-13) - 1`` is::
  3594. 7.5000000000028125000000007031250000001318...*10**-13.
  3595. Here is what ``expm1(7.5e-13)`` gives:
  3596. >>> expm1(7.5e-13)
  3597. 7.5000000000028135e-13
  3598. Compare that to ``exp(7.5e-13) - 1``, where the subtraction results in
  3599. a "catastrophic" loss of precision:
  3600. >>> np.exp(7.5e-13) - 1
  3601. 7.5006667543675576e-13
  3602. """)
  3603. add_newdoc("expn",
  3604. r"""
  3605. expn(n, x, out=None)
  3606. Generalized exponential integral En.
  3607. For integer :math:`n \geq 0` and real :math:`x \geq 0` the
  3608. generalized exponential integral is defined as [dlmf]_
  3609. .. math::
  3610. E_n(x) = x^{n - 1} \int_x^\infty \frac{e^{-t}}{t^n} dt.
  3611. Parameters
  3612. ----------
  3613. n : array_like
  3614. Non-negative integers
  3615. x : array_like
  3616. Real argument
  3617. out : ndarray, optional
  3618. Optional output array for the function results
  3619. Returns
  3620. -------
  3621. scalar or ndarray
  3622. Values of the generalized exponential integral
  3623. See Also
  3624. --------
  3625. exp1 : special case of :math:`E_n` for :math:`n = 1`
  3626. expi : related to :math:`E_n` when :math:`n = 1`
  3627. References
  3628. ----------
  3629. .. [dlmf] Digital Library of Mathematical Functions, 8.19.2
  3630. https://dlmf.nist.gov/8.19#E2
  3631. Examples
  3632. --------
  3633. >>> import numpy as np
  3634. >>> import scipy.special as sc
  3635. Its domain is nonnegative n and x.
  3636. >>> sc.expn(-1, 1.0), sc.expn(1, -1.0)
  3637. (nan, nan)
  3638. It has a pole at ``x = 0`` for ``n = 1, 2``; for larger ``n`` it
  3639. is equal to ``1 / (n - 1)``.
  3640. >>> sc.expn([0, 1, 2, 3, 4], 0)
  3641. array([ inf, inf, 1. , 0.5 , 0.33333333])
  3642. For n equal to 0 it reduces to ``exp(-x) / x``.
  3643. >>> x = np.array([1, 2, 3, 4])
  3644. >>> sc.expn(0, x)
  3645. array([0.36787944, 0.06766764, 0.01659569, 0.00457891])
  3646. >>> np.exp(-x) / x
  3647. array([0.36787944, 0.06766764, 0.01659569, 0.00457891])
  3648. For n equal to 1 it reduces to `exp1`.
  3649. >>> sc.expn(1, x)
  3650. array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
  3651. >>> sc.exp1(x)
  3652. array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
  3653. """)
  3654. add_newdoc("exprel",
  3655. r"""
  3656. exprel(x, out=None)
  3657. Relative error exponential, ``(exp(x) - 1)/x``.
  3658. When `x` is near zero, ``exp(x)`` is near 1, so the numerical calculation
  3659. of ``exp(x) - 1`` can suffer from catastrophic loss of precision.
  3660. ``exprel(x)`` is implemented to avoid the loss of precision that occurs when
  3661. `x` is near zero.
  3662. Parameters
  3663. ----------
  3664. x : ndarray
  3665. Input array. `x` must contain real numbers.
  3666. out : ndarray, optional
  3667. Optional output array for the function values
  3668. Returns
  3669. -------
  3670. scalar or ndarray
  3671. ``(exp(x) - 1)/x``, computed element-wise.
  3672. See Also
  3673. --------
  3674. expm1
  3675. Notes
  3676. -----
  3677. .. versionadded:: 0.17.0
  3678. Examples
  3679. --------
  3680. >>> import numpy as np
  3681. >>> from scipy.special import exprel
  3682. >>> exprel(0.01)
  3683. 1.0050167084168056
  3684. >>> exprel([-0.25, -0.1, 0, 0.1, 0.25])
  3685. array([ 0.88479687, 0.95162582, 1. , 1.05170918, 1.13610167])
  3686. Compare ``exprel(5e-9)`` to the naive calculation. The exact value
  3687. is ``1.00000000250000000416...``.
  3688. >>> exprel(5e-9)
  3689. 1.0000000025
  3690. >>> (np.exp(5e-9) - 1)/5e-9
  3691. 0.99999999392252903
  3692. """)
  3693. add_newdoc("fdtr",
  3694. r"""
  3695. fdtr(dfn, dfd, x, out=None)
  3696. F cumulative distribution function.
  3697. Returns the value of the cumulative distribution function of the
  3698. F-distribution, also known as Snedecor's F-distribution or the
  3699. Fisher-Snedecor distribution.
  3700. The F-distribution with parameters :math:`d_n` and :math:`d_d` is the
  3701. distribution of the random variable,
  3702. .. math::
  3703. X = \frac{U_n/d_n}{U_d/d_d},
  3704. where :math:`U_n` and :math:`U_d` are random variables distributed
  3705. :math:`\chi^2`, with :math:`d_n` and :math:`d_d` degrees of freedom,
  3706. respectively.
  3707. Parameters
  3708. ----------
  3709. dfn : array_like
  3710. First parameter (positive float).
  3711. dfd : array_like
  3712. Second parameter (positive float).
  3713. x : array_like
  3714. Argument (nonnegative float).
  3715. out : ndarray, optional
  3716. Optional output array for the function values
  3717. Returns
  3718. -------
  3719. y : scalar or ndarray
  3720. The CDF of the F-distribution with parameters `dfn` and `dfd` at `x`.
  3721. See Also
  3722. --------
  3723. fdtrc : F distribution survival function
  3724. fdtri : F distribution inverse cumulative distribution
  3725. scipy.stats.f : F distribution
  3726. Notes
  3727. -----
  3728. The regularized incomplete beta function is used, according to the
  3729. formula,
  3730. .. math::
  3731. F(d_n, d_d; x) = I_{xd_n/(d_d + xd_n)}(d_n/2, d_d/2).
  3732. Wrapper for the Cephes [1]_ routine `fdtr`. The F distribution is also
  3733. available as `scipy.stats.f`. Calling `fdtr` directly can improve
  3734. performance compared to the ``cdf`` method of `scipy.stats.f` (see last
  3735. example below).
  3736. References
  3737. ----------
  3738. .. [1] Cephes Mathematical Functions Library,
  3739. http://www.netlib.org/cephes/
  3740. Examples
  3741. --------
  3742. Calculate the function for ``dfn=1`` and ``dfd=2`` at ``x=1``.
  3743. >>> import numpy as np
  3744. >>> from scipy.special import fdtr
  3745. >>> fdtr(1, 2, 1)
  3746. 0.5773502691896258
  3747. Calculate the function at several points by providing a NumPy array for
  3748. `x`.
  3749. >>> x = np.array([0.5, 2., 3.])
  3750. >>> fdtr(1, 2, x)
  3751. array([0.4472136 , 0.70710678, 0.77459667])
  3752. Plot the function for several parameter sets.
  3753. >>> import matplotlib.pyplot as plt
  3754. >>> dfn_parameters = [1, 5, 10, 50]
  3755. >>> dfd_parameters = [1, 1, 2, 3]
  3756. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  3757. >>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
  3758. ... linestyles))
  3759. >>> x = np.linspace(0, 30, 1000)
  3760. >>> fig, ax = plt.subplots()
  3761. >>> for parameter_set in parameters_list:
  3762. ... dfn, dfd, style = parameter_set
  3763. ... fdtr_vals = fdtr(dfn, dfd, x)
  3764. ... ax.plot(x, fdtr_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
  3765. ... ls=style)
  3766. >>> ax.legend()
  3767. >>> ax.set_xlabel("$x$")
  3768. >>> ax.set_title("F distribution cumulative distribution function")
  3769. >>> plt.show()
  3770. The F distribution is also available as `scipy.stats.f`. Using `fdtr`
  3771. directly can be much faster than calling the ``cdf`` method of
  3772. `scipy.stats.f`, especially for small arrays or individual values.
  3773. To get the same results one must use the following parametrization:
  3774. ``stats.f(dfn, dfd).cdf(x)=fdtr(dfn, dfd, x)``.
  3775. >>> from scipy.stats import f
  3776. >>> dfn, dfd = 1, 2
  3777. >>> x = 1
  3778. >>> fdtr_res = fdtr(dfn, dfd, x) # this will often be faster than below
  3779. >>> f_dist_res = f(dfn, dfd).cdf(x)
  3780. >>> fdtr_res == f_dist_res # test that results are equal
  3781. True
  3782. """)
  3783. add_newdoc("fdtrc",
  3784. r"""
  3785. fdtrc(dfn, dfd, x, out=None)
  3786. F survival function.
  3787. Returns the complemented F-distribution function (the integral of the
  3788. density from `x` to infinity).
  3789. Parameters
  3790. ----------
  3791. dfn : array_like
  3792. First parameter (positive float).
  3793. dfd : array_like
  3794. Second parameter (positive float).
  3795. x : array_like
  3796. Argument (nonnegative float).
  3797. out : ndarray, optional
  3798. Optional output array for the function values
  3799. Returns
  3800. -------
  3801. y : scalar or ndarray
  3802. The complemented F-distribution function with parameters `dfn` and
  3803. `dfd` at `x`.
  3804. See Also
  3805. --------
  3806. fdtr : F distribution cumulative distribution function
  3807. fdtri : F distribution inverse cumulative distribution function
  3808. scipy.stats.f : F distribution
  3809. Notes
  3810. -----
  3811. The regularized incomplete beta function is used, according to the
  3812. formula,
  3813. .. math::
  3814. F(d_n, d_d; x) = I_{d_d/(d_d + xd_n)}(d_d/2, d_n/2).
  3815. Wrapper for the Cephes [1]_ routine `fdtrc`. The F distribution is also
  3816. available as `scipy.stats.f`. Calling `fdtrc` directly can improve
  3817. performance compared to the ``sf`` method of `scipy.stats.f` (see last
  3818. example below).
  3819. References
  3820. ----------
  3821. .. [1] Cephes Mathematical Functions Library,
  3822. http://www.netlib.org/cephes/
  3823. Examples
  3824. --------
  3825. Calculate the function for ``dfn=1`` and ``dfd=2`` at ``x=1``.
  3826. >>> import numpy as np
  3827. >>> from scipy.special import fdtrc
  3828. >>> fdtrc(1, 2, 1)
  3829. 0.42264973081037427
  3830. Calculate the function at several points by providing a NumPy array for
  3831. `x`.
  3832. >>> x = np.array([0.5, 2., 3.])
  3833. >>> fdtrc(1, 2, x)
  3834. array([0.5527864 , 0.29289322, 0.22540333])
  3835. Plot the function for several parameter sets.
  3836. >>> import matplotlib.pyplot as plt
  3837. >>> dfn_parameters = [1, 5, 10, 50]
  3838. >>> dfd_parameters = [1, 1, 2, 3]
  3839. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  3840. >>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
  3841. ... linestyles))
  3842. >>> x = np.linspace(0, 30, 1000)
  3843. >>> fig, ax = plt.subplots()
  3844. >>> for parameter_set in parameters_list:
  3845. ... dfn, dfd, style = parameter_set
  3846. ... fdtrc_vals = fdtrc(dfn, dfd, x)
  3847. ... ax.plot(x, fdtrc_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
  3848. ... ls=style)
  3849. >>> ax.legend()
  3850. >>> ax.set_xlabel("$x$")
  3851. >>> ax.set_title("F distribution survival function")
  3852. >>> plt.show()
  3853. The F distribution is also available as `scipy.stats.f`. Using `fdtrc`
  3854. directly can be much faster than calling the ``sf`` method of
  3855. `scipy.stats.f`, especially for small arrays or individual values.
  3856. To get the same results one must use the following parametrization:
  3857. ``stats.f(dfn, dfd).sf(x)=fdtrc(dfn, dfd, x)``.
  3858. >>> from scipy.stats import f
  3859. >>> dfn, dfd = 1, 2
  3860. >>> x = 1
  3861. >>> fdtrc_res = fdtrc(dfn, dfd, x) # this will often be faster than below
  3862. >>> f_dist_res = f(dfn, dfd).sf(x)
  3863. >>> f_dist_res == fdtrc_res # test that results are equal
  3864. True
  3865. """)
  3866. add_newdoc("fdtri",
  3867. r"""
  3868. fdtri(dfn, dfd, p, out=None)
  3869. The `p`-th quantile of the F-distribution.
  3870. This function is the inverse of the F-distribution CDF, `fdtr`, returning
  3871. the `x` such that `fdtr(dfn, dfd, x) = p`.
  3872. Parameters
  3873. ----------
  3874. dfn : array_like
  3875. First parameter (positive float).
  3876. dfd : array_like
  3877. Second parameter (positive float).
  3878. p : array_like
  3879. Cumulative probability, in [0, 1].
  3880. out : ndarray, optional
  3881. Optional output array for the function values
  3882. Returns
  3883. -------
  3884. x : scalar or ndarray
  3885. The quantile corresponding to `p`.
  3886. See Also
  3887. --------
  3888. fdtr : F distribution cumulative distribution function
  3889. fdtrc : F distribution survival function
  3890. scipy.stats.f : F distribution
  3891. Notes
  3892. -----
  3893. The computation is carried out using the relation to the inverse
  3894. regularized beta function, :math:`I^{-1}_x(a, b)`. Let
  3895. :math:`z = I^{-1}_p(d_d/2, d_n/2).` Then,
  3896. .. math::
  3897. x = \frac{d_d (1 - z)}{d_n z}.
  3898. If `p` is such that :math:`x < 0.5`, the following relation is used
  3899. instead for improved stability: let
  3900. :math:`z' = I^{-1}_{1 - p}(d_n/2, d_d/2).` Then,
  3901. .. math::
  3902. x = \frac{d_d z'}{d_n (1 - z')}.
  3903. Wrapper for the Cephes [1]_ routine `fdtri`.
  3904. The F distribution is also available as `scipy.stats.f`. Calling
  3905. `fdtri` directly can improve performance compared to the ``ppf``
  3906. method of `scipy.stats.f` (see last example below).
  3907. References
  3908. ----------
  3909. .. [1] Cephes Mathematical Functions Library,
  3910. http://www.netlib.org/cephes/
  3911. Examples
  3912. --------
  3913. `fdtri` represents the inverse of the F distribution CDF which is
  3914. available as `fdtr`. Here, we calculate the CDF for ``df1=1``, ``df2=2``
  3915. at ``x=3``. `fdtri` then returns ``3`` given the same values for `df1`,
  3916. `df2` and the computed CDF value.
  3917. >>> import numpy as np
  3918. >>> from scipy.special import fdtri, fdtr
  3919. >>> df1, df2 = 1, 2
  3920. >>> x = 3
  3921. >>> cdf_value = fdtr(df1, df2, x)
  3922. >>> fdtri(df1, df2, cdf_value)
  3923. 3.000000000000006
  3924. Calculate the function at several points by providing a NumPy array for
  3925. `x`.
  3926. >>> x = np.array([0.1, 0.4, 0.7])
  3927. >>> fdtri(1, 2, x)
  3928. array([0.02020202, 0.38095238, 1.92156863])
  3929. Plot the function for several parameter sets.
  3930. >>> import matplotlib.pyplot as plt
  3931. >>> dfn_parameters = [50, 10, 1, 50]
  3932. >>> dfd_parameters = [0.5, 1, 1, 5]
  3933. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  3934. >>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
  3935. ... linestyles))
  3936. >>> x = np.linspace(0, 1, 1000)
  3937. >>> fig, ax = plt.subplots()
  3938. >>> for parameter_set in parameters_list:
  3939. ... dfn, dfd, style = parameter_set
  3940. ... fdtri_vals = fdtri(dfn, dfd, x)
  3941. ... ax.plot(x, fdtri_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
  3942. ... ls=style)
  3943. >>> ax.legend()
  3944. >>> ax.set_xlabel("$x$")
  3945. >>> title = "F distribution inverse cumulative distribution function"
  3946. >>> ax.set_title(title)
  3947. >>> ax.set_ylim(0, 30)
  3948. >>> plt.show()
  3949. The F distribution is also available as `scipy.stats.f`. Using `fdtri`
  3950. directly can be much faster than calling the ``ppf`` method of
  3951. `scipy.stats.f`, especially for small arrays or individual values.
  3952. To get the same results one must use the following parametrization:
  3953. ``stats.f(dfn, dfd).ppf(x)=fdtri(dfn, dfd, x)``.
  3954. >>> from scipy.stats import f
  3955. >>> dfn, dfd = 1, 2
  3956. >>> x = 0.7
  3957. >>> fdtri_res = fdtri(dfn, dfd, x) # this will often be faster than below
  3958. >>> f_dist_res = f(dfn, dfd).ppf(x)
  3959. >>> f_dist_res == fdtri_res # test that results are equal
  3960. True
  3961. """)
  3962. add_newdoc("fdtridfd",
  3963. """
  3964. fdtridfd(dfn, p, x, out=None)
  3965. Inverse to `fdtr` vs dfd
  3966. Finds the F density argument dfd such that ``fdtr(dfn, dfd, x) == p``.
  3967. Parameters
  3968. ----------
  3969. dfn : array_like
  3970. First parameter (positive float).
  3971. p : array_like
  3972. Cumulative probability, in [0, 1].
  3973. x : array_like
  3974. Argument (nonnegative float).
  3975. out : ndarray, optional
  3976. Optional output array for the function values
  3977. Returns
  3978. -------
  3979. dfd : scalar or ndarray
  3980. `dfd` such that ``fdtr(dfn, dfd, x) == p``.
  3981. See Also
  3982. --------
  3983. fdtr, fdtrc, fdtri
  3984. """)
  3985. '''
  3986. commented out as fdtridfn seems to have bugs and is not in functions.json
  3987. see: https://github.com/scipy/scipy/pull/15622#discussion_r811440983
  3988. add_newdoc(
  3989. "fdtridfn",
  3990. """
  3991. fdtridfn(p, dfd, x, out=None)
  3992. Inverse to `fdtr` vs dfn
  3993. finds the F density argument dfn such that ``fdtr(dfn, dfd, x) == p``.
  3994. Parameters
  3995. ----------
  3996. p : array_like
  3997. Cumulative probability, in [0, 1].
  3998. dfd : array_like
  3999. Second parameter (positive float).
  4000. x : array_like
  4001. Argument (nonnegative float).
  4002. out : ndarray, optional
  4003. Optional output array for the function values
  4004. Returns
  4005. -------
  4006. dfn : scalar or ndarray
  4007. `dfn` such that ``fdtr(dfn, dfd, x) == p``.
  4008. See Also
  4009. --------
  4010. fdtr, fdtrc, fdtri, fdtridfd
  4011. """)
  4012. '''
  4013. add_newdoc("fresnel",
  4014. r"""
  4015. fresnel(z, out=None)
  4016. Fresnel integrals.
  4017. The Fresnel integrals are defined as
  4018. .. math::
  4019. S(z) &= \int_0^z \sin(\pi t^2 /2) dt \\
  4020. C(z) &= \int_0^z \cos(\pi t^2 /2) dt.
  4021. See [dlmf]_ for details.
  4022. Parameters
  4023. ----------
  4024. z : array_like
  4025. Real or complex valued argument
  4026. out : 2-tuple of ndarrays, optional
  4027. Optional output arrays for the function results
  4028. Returns
  4029. -------
  4030. S, C : 2-tuple of scalar or ndarray
  4031. Values of the Fresnel integrals
  4032. See Also
  4033. --------
  4034. fresnel_zeros : zeros of the Fresnel integrals
  4035. References
  4036. ----------
  4037. .. [dlmf] NIST Digital Library of Mathematical Functions
  4038. https://dlmf.nist.gov/7.2#iii
  4039. Examples
  4040. --------
  4041. >>> import numpy as np
  4042. >>> import scipy.special as sc
  4043. As z goes to infinity along the real axis, S and C converge to 0.5.
  4044. >>> S, C = sc.fresnel([0.1, 1, 10, 100, np.inf])
  4045. >>> S
  4046. array([0.00052359, 0.43825915, 0.46816998, 0.4968169 , 0.5 ])
  4047. >>> C
  4048. array([0.09999753, 0.7798934 , 0.49989869, 0.4999999 , 0.5 ])
  4049. They are related to the error function `erf`.
  4050. >>> z = np.array([1, 2, 3, 4])
  4051. >>> zeta = 0.5 * np.sqrt(np.pi) * (1 - 1j) * z
  4052. >>> S, C = sc.fresnel(z)
  4053. >>> C + 1j*S
  4054. array([0.7798934 +0.43825915j, 0.48825341+0.34341568j,
  4055. 0.60572079+0.496313j , 0.49842603+0.42051575j])
  4056. >>> 0.5 * (1 + 1j) * sc.erf(zeta)
  4057. array([0.7798934 +0.43825915j, 0.48825341+0.34341568j,
  4058. 0.60572079+0.496313j , 0.49842603+0.42051575j])
  4059. """)
  4060. add_newdoc("gamma",
  4061. r"""
  4062. gamma(z, out=None)
  4063. gamma function.
  4064. The gamma function is defined as
  4065. .. math::
  4066. \Gamma(z) = \int_0^\infty t^{z-1} e^{-t} dt
  4067. for :math:`\Re(z) > 0` and is extended to the rest of the complex
  4068. plane by analytic continuation. See [dlmf]_ for more details.
  4069. Parameters
  4070. ----------
  4071. z : array_like
  4072. Real or complex valued argument
  4073. out : ndarray, optional
  4074. Optional output array for the function values
  4075. Returns
  4076. -------
  4077. scalar or ndarray
  4078. Values of the gamma function
  4079. Notes
  4080. -----
  4081. The gamma function is often referred to as the generalized
  4082. factorial since :math:`\Gamma(n + 1) = n!` for natural numbers
  4083. :math:`n`. More generally it satisfies the recurrence relation
  4084. :math:`\Gamma(z + 1) = z \cdot \Gamma(z)` for complex :math:`z`,
  4085. which, combined with the fact that :math:`\Gamma(1) = 1`, implies
  4086. the above identity for :math:`z = n`.
  4087. References
  4088. ----------
  4089. .. [dlmf] NIST Digital Library of Mathematical Functions
  4090. https://dlmf.nist.gov/5.2#E1
  4091. Examples
  4092. --------
  4093. >>> import numpy as np
  4094. >>> from scipy.special import gamma, factorial
  4095. >>> gamma([0, 0.5, 1, 5])
  4096. array([ inf, 1.77245385, 1. , 24. ])
  4097. >>> z = 2.5 + 1j
  4098. >>> gamma(z)
  4099. (0.77476210455108352+0.70763120437959293j)
  4100. >>> gamma(z+1), z*gamma(z) # Recurrence property
  4101. ((1.2292740569981171+2.5438401155000685j),
  4102. (1.2292740569981158+2.5438401155000658j))
  4103. >>> gamma(0.5)**2 # gamma(0.5) = sqrt(pi)
  4104. 3.1415926535897927
  4105. Plot gamma(x) for real x
  4106. >>> x = np.linspace(-3.5, 5.5, 2251)
  4107. >>> y = gamma(x)
  4108. >>> import matplotlib.pyplot as plt
  4109. >>> plt.plot(x, y, 'b', alpha=0.6, label='gamma(x)')
  4110. >>> k = np.arange(1, 7)
  4111. >>> plt.plot(k, factorial(k-1), 'k*', alpha=0.6,
  4112. ... label='(x-1)!, x = 1, 2, ...')
  4113. >>> plt.xlim(-3.5, 5.5)
  4114. >>> plt.ylim(-10, 25)
  4115. >>> plt.grid()
  4116. >>> plt.xlabel('x')
  4117. >>> plt.legend(loc='lower right')
  4118. >>> plt.show()
  4119. """)
  4120. add_newdoc("gammainc",
  4121. r"""
  4122. gammainc(a, x, out=None)
  4123. Regularized lower incomplete gamma function.
  4124. It is defined as
  4125. .. math::
  4126. P(a, x) = \frac{1}{\Gamma(a)} \int_0^x t^{a - 1}e^{-t} dt
  4127. for :math:`a > 0` and :math:`x \geq 0`. See [dlmf]_ for details.
  4128. Parameters
  4129. ----------
  4130. a : array_like
  4131. Positive parameter
  4132. x : array_like
  4133. Nonnegative argument
  4134. out : ndarray, optional
  4135. Optional output array for the function values
  4136. Returns
  4137. -------
  4138. scalar or ndarray
  4139. Values of the lower incomplete gamma function
  4140. Notes
  4141. -----
  4142. The function satisfies the relation ``gammainc(a, x) +
  4143. gammaincc(a, x) = 1`` where `gammaincc` is the regularized upper
  4144. incomplete gamma function.
  4145. The implementation largely follows that of [boost]_.
  4146. See also
  4147. --------
  4148. gammaincc : regularized upper incomplete gamma function
  4149. gammaincinv : inverse of the regularized lower incomplete gamma function
  4150. gammainccinv : inverse of the regularized upper incomplete gamma function
  4151. References
  4152. ----------
  4153. .. [dlmf] NIST Digital Library of Mathematical functions
  4154. https://dlmf.nist.gov/8.2#E4
  4155. .. [boost] Maddock et. al., "Incomplete Gamma Functions",
  4156. https://www.boost.org/doc/libs/1_61_0/libs/math/doc/html/math_toolkit/sf_gamma/igamma.html
  4157. Examples
  4158. --------
  4159. >>> import scipy.special as sc
  4160. It is the CDF of the gamma distribution, so it starts at 0 and
  4161. monotonically increases to 1.
  4162. >>> sc.gammainc(0.5, [0, 1, 10, 100])
  4163. array([0. , 0.84270079, 0.99999226, 1. ])
  4164. It is equal to one minus the upper incomplete gamma function.
  4165. >>> a, x = 0.5, 0.4
  4166. >>> sc.gammainc(a, x)
  4167. 0.6289066304773024
  4168. >>> 1 - sc.gammaincc(a, x)
  4169. 0.6289066304773024
  4170. """)
  4171. add_newdoc("gammaincc",
  4172. r"""
  4173. gammaincc(a, x, out=None)
  4174. Regularized upper incomplete gamma function.
  4175. It is defined as
  4176. .. math::
  4177. Q(a, x) = \frac{1}{\Gamma(a)} \int_x^\infty t^{a - 1}e^{-t} dt
  4178. for :math:`a > 0` and :math:`x \geq 0`. See [dlmf]_ for details.
  4179. Parameters
  4180. ----------
  4181. a : array_like
  4182. Positive parameter
  4183. x : array_like
  4184. Nonnegative argument
  4185. out : ndarray, optional
  4186. Optional output array for the function values
  4187. Returns
  4188. -------
  4189. scalar or ndarray
  4190. Values of the upper incomplete gamma function
  4191. Notes
  4192. -----
  4193. The function satisfies the relation ``gammainc(a, x) +
  4194. gammaincc(a, x) = 1`` where `gammainc` is the regularized lower
  4195. incomplete gamma function.
  4196. The implementation largely follows that of [boost]_.
  4197. See also
  4198. --------
  4199. gammainc : regularized lower incomplete gamma function
  4200. gammaincinv : inverse of the regularized lower incomplete gamma function
  4201. gammainccinv : inverse of the regularized upper incomplete gamma function
  4202. References
  4203. ----------
  4204. .. [dlmf] NIST Digital Library of Mathematical functions
  4205. https://dlmf.nist.gov/8.2#E4
  4206. .. [boost] Maddock et. al., "Incomplete Gamma Functions",
  4207. https://www.boost.org/doc/libs/1_61_0/libs/math/doc/html/math_toolkit/sf_gamma/igamma.html
  4208. Examples
  4209. --------
  4210. >>> import scipy.special as sc
  4211. It is the survival function of the gamma distribution, so it
  4212. starts at 1 and monotonically decreases to 0.
  4213. >>> sc.gammaincc(0.5, [0, 1, 10, 100, 1000])
  4214. array([1.00000000e+00, 1.57299207e-01, 7.74421643e-06, 2.08848758e-45,
  4215. 0.00000000e+00])
  4216. It is equal to one minus the lower incomplete gamma function.
  4217. >>> a, x = 0.5, 0.4
  4218. >>> sc.gammaincc(a, x)
  4219. 0.37109336952269756
  4220. >>> 1 - sc.gammainc(a, x)
  4221. 0.37109336952269756
  4222. """)
  4223. add_newdoc("gammainccinv",
  4224. """
  4225. gammainccinv(a, y, out=None)
  4226. Inverse of the regularized upper incomplete gamma function.
  4227. Given an input :math:`y` between 0 and 1, returns :math:`x` such
  4228. that :math:`y = Q(a, x)`. Here :math:`Q` is the regularized upper
  4229. incomplete gamma function; see `gammaincc`. This is well-defined
  4230. because the upper incomplete gamma function is monotonic as can
  4231. be seen from its definition in [dlmf]_.
  4232. Parameters
  4233. ----------
  4234. a : array_like
  4235. Positive parameter
  4236. y : array_like
  4237. Argument between 0 and 1, inclusive
  4238. out : ndarray, optional
  4239. Optional output array for the function values
  4240. Returns
  4241. -------
  4242. scalar or ndarray
  4243. Values of the inverse of the upper incomplete gamma function
  4244. See Also
  4245. --------
  4246. gammaincc : regularized upper incomplete gamma function
  4247. gammainc : regularized lower incomplete gamma function
  4248. gammaincinv : inverse of the regularized lower incomplete gamma function
  4249. References
  4250. ----------
  4251. .. [dlmf] NIST Digital Library of Mathematical Functions
  4252. https://dlmf.nist.gov/8.2#E4
  4253. Examples
  4254. --------
  4255. >>> import scipy.special as sc
  4256. It starts at infinity and monotonically decreases to 0.
  4257. >>> sc.gammainccinv(0.5, [0, 0.1, 0.5, 1])
  4258. array([ inf, 1.35277173, 0.22746821, 0. ])
  4259. It inverts the upper incomplete gamma function.
  4260. >>> a, x = 0.5, [0, 0.1, 0.5, 1]
  4261. >>> sc.gammaincc(a, sc.gammainccinv(a, x))
  4262. array([0. , 0.1, 0.5, 1. ])
  4263. >>> a, x = 0.5, [0, 10, 50]
  4264. >>> sc.gammainccinv(a, sc.gammaincc(a, x))
  4265. array([ 0., 10., 50.])
  4266. """)
  4267. add_newdoc("gammaincinv",
  4268. """
  4269. gammaincinv(a, y, out=None)
  4270. Inverse to the regularized lower incomplete gamma function.
  4271. Given an input :math:`y` between 0 and 1, returns :math:`x` such
  4272. that :math:`y = P(a, x)`. Here :math:`P` is the regularized lower
  4273. incomplete gamma function; see `gammainc`. This is well-defined
  4274. because the lower incomplete gamma function is monotonic as can be
  4275. seen from its definition in [dlmf]_.
  4276. Parameters
  4277. ----------
  4278. a : array_like
  4279. Positive parameter
  4280. y : array_like
  4281. Parameter between 0 and 1, inclusive
  4282. out : ndarray, optional
  4283. Optional output array for the function values
  4284. Returns
  4285. -------
  4286. scalar or ndarray
  4287. Values of the inverse of the lower incomplete gamma function
  4288. See Also
  4289. --------
  4290. gammainc : regularized lower incomplete gamma function
  4291. gammaincc : regularized upper incomplete gamma function
  4292. gammainccinv : inverse of the regularized upper incomplete gamma function
  4293. References
  4294. ----------
  4295. .. [dlmf] NIST Digital Library of Mathematical Functions
  4296. https://dlmf.nist.gov/8.2#E4
  4297. Examples
  4298. --------
  4299. >>> import scipy.special as sc
  4300. It starts at 0 and monotonically increases to infinity.
  4301. >>> sc.gammaincinv(0.5, [0, 0.1 ,0.5, 1])
  4302. array([0. , 0.00789539, 0.22746821, inf])
  4303. It inverts the lower incomplete gamma function.
  4304. >>> a, x = 0.5, [0, 0.1, 0.5, 1]
  4305. >>> sc.gammainc(a, sc.gammaincinv(a, x))
  4306. array([0. , 0.1, 0.5, 1. ])
  4307. >>> a, x = 0.5, [0, 10, 25]
  4308. >>> sc.gammaincinv(a, sc.gammainc(a, x))
  4309. array([ 0. , 10. , 25.00001465])
  4310. """)
  4311. add_newdoc("gammaln",
  4312. r"""
  4313. gammaln(x, out=None)
  4314. Logarithm of the absolute value of the gamma function.
  4315. Defined as
  4316. .. math::
  4317. \ln(\lvert\Gamma(x)\rvert)
  4318. where :math:`\Gamma` is the gamma function. For more details on
  4319. the gamma function, see [dlmf]_.
  4320. Parameters
  4321. ----------
  4322. x : array_like
  4323. Real argument
  4324. out : ndarray, optional
  4325. Optional output array for the function results
  4326. Returns
  4327. -------
  4328. scalar or ndarray
  4329. Values of the log of the absolute value of gamma
  4330. See Also
  4331. --------
  4332. gammasgn : sign of the gamma function
  4333. loggamma : principal branch of the logarithm of the gamma function
  4334. Notes
  4335. -----
  4336. It is the same function as the Python standard library function
  4337. :func:`math.lgamma`.
  4338. When used in conjunction with `gammasgn`, this function is useful
  4339. for working in logspace on the real axis without having to deal
  4340. with complex numbers via the relation ``exp(gammaln(x)) =
  4341. gammasgn(x) * gamma(x)``.
  4342. For complex-valued log-gamma, use `loggamma` instead of `gammaln`.
  4343. References
  4344. ----------
  4345. .. [dlmf] NIST Digital Library of Mathematical Functions
  4346. https://dlmf.nist.gov/5
  4347. Examples
  4348. --------
  4349. >>> import numpy as np
  4350. >>> import scipy.special as sc
  4351. It has two positive zeros.
  4352. >>> sc.gammaln([1, 2])
  4353. array([0., 0.])
  4354. It has poles at nonpositive integers.
  4355. >>> sc.gammaln([0, -1, -2, -3, -4])
  4356. array([inf, inf, inf, inf, inf])
  4357. It asymptotically approaches ``x * log(x)`` (Stirling's formula).
  4358. >>> x = np.array([1e10, 1e20, 1e40, 1e80])
  4359. >>> sc.gammaln(x)
  4360. array([2.20258509e+11, 4.50517019e+21, 9.11034037e+41, 1.83206807e+82])
  4361. >>> x * np.log(x)
  4362. array([2.30258509e+11, 4.60517019e+21, 9.21034037e+41, 1.84206807e+82])
  4363. """)
  4364. add_newdoc("gammasgn",
  4365. r"""
  4366. gammasgn(x, out=None)
  4367. Sign of the gamma function.
  4368. It is defined as
  4369. .. math::
  4370. \text{gammasgn}(x) =
  4371. \begin{cases}
  4372. +1 & \Gamma(x) > 0 \\
  4373. -1 & \Gamma(x) < 0
  4374. \end{cases}
  4375. where :math:`\Gamma` is the gamma function; see `gamma`. This
  4376. definition is complete since the gamma function is never zero;
  4377. see the discussion after [dlmf]_.
  4378. Parameters
  4379. ----------
  4380. x : array_like
  4381. Real argument
  4382. out : ndarray, optional
  4383. Optional output array for the function values
  4384. Returns
  4385. -------
  4386. scalar or ndarray
  4387. Sign of the gamma function
  4388. Notes
  4389. -----
  4390. The gamma function can be computed as ``gammasgn(x) *
  4391. np.exp(gammaln(x))``.
  4392. See Also
  4393. --------
  4394. gamma : the gamma function
  4395. gammaln : log of the absolute value of the gamma function
  4396. loggamma : analytic continuation of the log of the gamma function
  4397. References
  4398. ----------
  4399. .. [dlmf] NIST Digital Library of Mathematical Functions
  4400. https://dlmf.nist.gov/5.2#E1
  4401. Examples
  4402. --------
  4403. >>> import numpy as np
  4404. >>> import scipy.special as sc
  4405. It is 1 for `x > 0`.
  4406. >>> sc.gammasgn([1, 2, 3, 4])
  4407. array([1., 1., 1., 1.])
  4408. It alternates between -1 and 1 for negative integers.
  4409. >>> sc.gammasgn([-0.5, -1.5, -2.5, -3.5])
  4410. array([-1., 1., -1., 1.])
  4411. It can be used to compute the gamma function.
  4412. >>> x = [1.5, 0.5, -0.5, -1.5]
  4413. >>> sc.gammasgn(x) * np.exp(sc.gammaln(x))
  4414. array([ 0.88622693, 1.77245385, -3.5449077 , 2.3632718 ])
  4415. >>> sc.gamma(x)
  4416. array([ 0.88622693, 1.77245385, -3.5449077 , 2.3632718 ])
  4417. """)
  4418. add_newdoc("gdtr",
  4419. r"""
  4420. gdtr(a, b, x, out=None)
  4421. Gamma distribution cumulative distribution function.
  4422. Returns the integral from zero to `x` of the gamma probability density
  4423. function,
  4424. .. math::
  4425. F = \int_0^x \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at}\,dt,
  4426. where :math:`\Gamma` is the gamma function.
  4427. Parameters
  4428. ----------
  4429. a : array_like
  4430. The rate parameter of the gamma distribution, sometimes denoted
  4431. :math:`\beta` (float). It is also the reciprocal of the scale
  4432. parameter :math:`\theta`.
  4433. b : array_like
  4434. The shape parameter of the gamma distribution, sometimes denoted
  4435. :math:`\alpha` (float).
  4436. x : array_like
  4437. The quantile (upper limit of integration; float).
  4438. out : ndarray, optional
  4439. Optional output array for the function values
  4440. See also
  4441. --------
  4442. gdtrc : 1 - CDF of the gamma distribution.
  4443. scipy.stats.gamma: Gamma distribution
  4444. Returns
  4445. -------
  4446. F : scalar or ndarray
  4447. The CDF of the gamma distribution with parameters `a` and `b`
  4448. evaluated at `x`.
  4449. Notes
  4450. -----
  4451. The evaluation is carried out using the relation to the incomplete gamma
  4452. integral (regularized gamma function).
  4453. Wrapper for the Cephes [1]_ routine `gdtr`. Calling `gdtr` directly can
  4454. improve performance compared to the ``cdf`` method of `scipy.stats.gamma`
  4455. (see last example below).
  4456. References
  4457. ----------
  4458. .. [1] Cephes Mathematical Functions Library,
  4459. http://www.netlib.org/cephes/
  4460. Examples
  4461. --------
  4462. Compute the function for ``a=1``, ``b=2`` at ``x=5``.
  4463. >>> import numpy as np
  4464. >>> from scipy.special import gdtr
  4465. >>> import matplotlib.pyplot as plt
  4466. >>> gdtr(1., 2., 5.)
  4467. 0.9595723180054873
  4468. Compute the function for ``a=1`` and ``b=2`` at several points by
  4469. providing a NumPy array for `x`.
  4470. >>> xvalues = np.array([1., 2., 3., 4])
  4471. >>> gdtr(1., 1., xvalues)
  4472. array([0.63212056, 0.86466472, 0.95021293, 0.98168436])
  4473. `gdtr` can evaluate different parameter sets by providing arrays with
  4474. broadcasting compatible shapes for `a`, `b` and `x`. Here we compute the
  4475. function for three different `a` at four positions `x` and ``b=3``,
  4476. resulting in a 3x4 array.
  4477. >>> a = np.array([[0.5], [1.5], [2.5]])
  4478. >>> x = np.array([1., 2., 3., 4])
  4479. >>> a.shape, x.shape
  4480. ((3, 1), (4,))
  4481. >>> gdtr(a, 3., x)
  4482. array([[0.01438768, 0.0803014 , 0.19115317, 0.32332358],
  4483. [0.19115317, 0.57680992, 0.82642193, 0.9380312 ],
  4484. [0.45618688, 0.87534798, 0.97974328, 0.9972306 ]])
  4485. Plot the function for four different parameter sets.
  4486. >>> a_parameters = [0.3, 1, 2, 6]
  4487. >>> b_parameters = [2, 10, 15, 20]
  4488. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  4489. >>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
  4490. >>> x = np.linspace(0, 30, 1000)
  4491. >>> fig, ax = plt.subplots()
  4492. >>> for parameter_set in parameters_list:
  4493. ... a, b, style = parameter_set
  4494. ... gdtr_vals = gdtr(a, b, x)
  4495. ... ax.plot(x, gdtr_vals, label=f"$a= {a},\, b={b}$", ls=style)
  4496. >>> ax.legend()
  4497. >>> ax.set_xlabel("$x$")
  4498. >>> ax.set_title("Gamma distribution cumulative distribution function")
  4499. >>> plt.show()
  4500. The gamma distribution is also available as `scipy.stats.gamma`. Using
  4501. `gdtr` directly can be much faster than calling the ``cdf`` method of
  4502. `scipy.stats.gamma`, especially for small arrays or individual values.
  4503. To get the same results one must use the following parametrization:
  4504. ``stats.gamma(b, scale=1/a).cdf(x)=gdtr(a, b, x)``.
  4505. >>> from scipy.stats import gamma
  4506. >>> a = 2.
  4507. >>> b = 3
  4508. >>> x = 1.
  4509. >>> gdtr_result = gdtr(a, b, x) # this will often be faster than below
  4510. >>> gamma_dist_result = gamma(b, scale=1/a).cdf(x)
  4511. >>> gdtr_result == gamma_dist_result # test that results are equal
  4512. True
  4513. """)
  4514. add_newdoc("gdtrc",
  4515. r"""
  4516. gdtrc(a, b, x, out=None)
  4517. Gamma distribution survival function.
  4518. Integral from `x` to infinity of the gamma probability density function,
  4519. .. math::
  4520. F = \int_x^\infty \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at}\,dt,
  4521. where :math:`\Gamma` is the gamma function.
  4522. Parameters
  4523. ----------
  4524. a : array_like
  4525. The rate parameter of the gamma distribution, sometimes denoted
  4526. :math:`\beta` (float). It is also the reciprocal of the scale
  4527. parameter :math:`\theta`.
  4528. b : array_like
  4529. The shape parameter of the gamma distribution, sometimes denoted
  4530. :math:`\alpha` (float).
  4531. x : array_like
  4532. The quantile (lower limit of integration; float).
  4533. out : ndarray, optional
  4534. Optional output array for the function values
  4535. Returns
  4536. -------
  4537. F : scalar or ndarray
  4538. The survival function of the gamma distribution with parameters `a`
  4539. and `b` evaluated at `x`.
  4540. See Also
  4541. --------
  4542. gdtr: Gamma distribution cumulative distribution function
  4543. scipy.stats.gamma: Gamma distribution
  4544. gdtrix
  4545. Notes
  4546. -----
  4547. The evaluation is carried out using the relation to the incomplete gamma
  4548. integral (regularized gamma function).
  4549. Wrapper for the Cephes [1]_ routine `gdtrc`. Calling `gdtrc` directly can
  4550. improve performance compared to the ``sf`` method of `scipy.stats.gamma`
  4551. (see last example below).
  4552. References
  4553. ----------
  4554. .. [1] Cephes Mathematical Functions Library,
  4555. http://www.netlib.org/cephes/
  4556. Examples
  4557. --------
  4558. Compute the function for ``a=1`` and ``b=2`` at ``x=5``.
  4559. >>> import numpy as np
  4560. >>> from scipy.special import gdtrc
  4561. >>> import matplotlib.pyplot as plt
  4562. >>> gdtrc(1., 2., 5.)
  4563. 0.04042768199451279
  4564. Compute the function for ``a=1``, ``b=2`` at several points by providing
  4565. a NumPy array for `x`.
  4566. >>> xvalues = np.array([1., 2., 3., 4])
  4567. >>> gdtrc(1., 1., xvalues)
  4568. array([0.36787944, 0.13533528, 0.04978707, 0.01831564])
  4569. `gdtrc` can evaluate different parameter sets by providing arrays with
  4570. broadcasting compatible shapes for `a`, `b` and `x`. Here we compute the
  4571. function for three different `a` at four positions `x` and ``b=3``,
  4572. resulting in a 3x4 array.
  4573. >>> a = np.array([[0.5], [1.5], [2.5]])
  4574. >>> x = np.array([1., 2., 3., 4])
  4575. >>> a.shape, x.shape
  4576. ((3, 1), (4,))
  4577. >>> gdtrc(a, 3., x)
  4578. array([[0.98561232, 0.9196986 , 0.80884683, 0.67667642],
  4579. [0.80884683, 0.42319008, 0.17357807, 0.0619688 ],
  4580. [0.54381312, 0.12465202, 0.02025672, 0.0027694 ]])
  4581. Plot the function for four different parameter sets.
  4582. >>> a_parameters = [0.3, 1, 2, 6]
  4583. >>> b_parameters = [2, 10, 15, 20]
  4584. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  4585. >>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
  4586. >>> x = np.linspace(0, 30, 1000)
  4587. >>> fig, ax = plt.subplots()
  4588. >>> for parameter_set in parameters_list:
  4589. ... a, b, style = parameter_set
  4590. ... gdtrc_vals = gdtrc(a, b, x)
  4591. ... ax.plot(x, gdtrc_vals, label=f"$a= {a},\, b={b}$", ls=style)
  4592. >>> ax.legend()
  4593. >>> ax.set_xlabel("$x$")
  4594. >>> ax.set_title("Gamma distribution survival function")
  4595. >>> plt.show()
  4596. The gamma distribution is also available as `scipy.stats.gamma`.
  4597. Using `gdtrc` directly can be much faster than calling the ``sf`` method
  4598. of `scipy.stats.gamma`, especially for small arrays or individual
  4599. values. To get the same results one must use the following parametrization:
  4600. ``stats.gamma(b, scale=1/a).sf(x)=gdtrc(a, b, x)``.
  4601. >>> from scipy.stats import gamma
  4602. >>> a = 2
  4603. >>> b = 3
  4604. >>> x = 1.
  4605. >>> gdtrc_result = gdtrc(a, b, x) # this will often be faster than below
  4606. >>> gamma_dist_result = gamma(b, scale=1/a).sf(x)
  4607. >>> gdtrc_result == gamma_dist_result # test that results are equal
  4608. True
  4609. """)
  4610. add_newdoc("gdtria",
  4611. """
  4612. gdtria(p, b, x, out=None)
  4613. Inverse of `gdtr` vs a.
  4614. Returns the inverse with respect to the parameter `a` of ``p =
  4615. gdtr(a, b, x)``, the cumulative distribution function of the gamma
  4616. distribution.
  4617. Parameters
  4618. ----------
  4619. p : array_like
  4620. Probability values.
  4621. b : array_like
  4622. `b` parameter values of `gdtr(a, b, x)`. `b` is the "shape" parameter
  4623. of the gamma distribution.
  4624. x : array_like
  4625. Nonnegative real values, from the domain of the gamma distribution.
  4626. out : ndarray, optional
  4627. If a fourth argument is given, it must be a numpy.ndarray whose size
  4628. matches the broadcast result of `a`, `b` and `x`. `out` is then the
  4629. array returned by the function.
  4630. Returns
  4631. -------
  4632. a : scalar or ndarray
  4633. Values of the `a` parameter such that `p = gdtr(a, b, x)`. `1/a`
  4634. is the "scale" parameter of the gamma distribution.
  4635. See Also
  4636. --------
  4637. gdtr : CDF of the gamma distribution.
  4638. gdtrib : Inverse with respect to `b` of `gdtr(a, b, x)`.
  4639. gdtrix : Inverse with respect to `x` of `gdtr(a, b, x)`.
  4640. Notes
  4641. -----
  4642. Wrapper for the CDFLIB [1]_ Fortran routine `cdfgam`.
  4643. The cumulative distribution function `p` is computed using a routine by
  4644. DiDinato and Morris [2]_. Computation of `a` involves a search for a value
  4645. that produces the desired value of `p`. The search relies on the
  4646. monotonicity of `p` with `a`.
  4647. References
  4648. ----------
  4649. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  4650. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  4651. Functions, Inverses, and Other Parameters.
  4652. .. [2] DiDinato, A. R. and Morris, A. H.,
  4653. Computation of the incomplete gamma function ratios and their
  4654. inverse. ACM Trans. Math. Softw. 12 (1986), 377-393.
  4655. Examples
  4656. --------
  4657. First evaluate `gdtr`.
  4658. >>> from scipy.special import gdtr, gdtria
  4659. >>> p = gdtr(1.2, 3.4, 5.6)
  4660. >>> print(p)
  4661. 0.94378087442
  4662. Verify the inverse.
  4663. >>> gdtria(p, 3.4, 5.6)
  4664. 1.2
  4665. """)
  4666. add_newdoc("gdtrib",
  4667. """
  4668. gdtrib(a, p, x, out=None)
  4669. Inverse of `gdtr` vs b.
  4670. Returns the inverse with respect to the parameter `b` of ``p =
  4671. gdtr(a, b, x)``, the cumulative distribution function of the gamma
  4672. distribution.
  4673. Parameters
  4674. ----------
  4675. a : array_like
  4676. `a` parameter values of `gdtr(a, b, x)`. `1/a` is the "scale"
  4677. parameter of the gamma distribution.
  4678. p : array_like
  4679. Probability values.
  4680. x : array_like
  4681. Nonnegative real values, from the domain of the gamma distribution.
  4682. out : ndarray, optional
  4683. If a fourth argument is given, it must be a numpy.ndarray whose size
  4684. matches the broadcast result of `a`, `b` and `x`. `out` is then the
  4685. array returned by the function.
  4686. Returns
  4687. -------
  4688. b : scalar or ndarray
  4689. Values of the `b` parameter such that `p = gdtr(a, b, x)`. `b` is
  4690. the "shape" parameter of the gamma distribution.
  4691. See Also
  4692. --------
  4693. gdtr : CDF of the gamma distribution.
  4694. gdtria : Inverse with respect to `a` of `gdtr(a, b, x)`.
  4695. gdtrix : Inverse with respect to `x` of `gdtr(a, b, x)`.
  4696. Notes
  4697. -----
  4698. Wrapper for the CDFLIB [1]_ Fortran routine `cdfgam`.
  4699. The cumulative distribution function `p` is computed using a routine by
  4700. DiDinato and Morris [2]_. Computation of `b` involves a search for a value
  4701. that produces the desired value of `p`. The search relies on the
  4702. monotonicity of `p` with `b`.
  4703. References
  4704. ----------
  4705. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  4706. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  4707. Functions, Inverses, and Other Parameters.
  4708. .. [2] DiDinato, A. R. and Morris, A. H.,
  4709. Computation of the incomplete gamma function ratios and their
  4710. inverse. ACM Trans. Math. Softw. 12 (1986), 377-393.
  4711. Examples
  4712. --------
  4713. First evaluate `gdtr`.
  4714. >>> from scipy.special import gdtr, gdtrib
  4715. >>> p = gdtr(1.2, 3.4, 5.6)
  4716. >>> print(p)
  4717. 0.94378087442
  4718. Verify the inverse.
  4719. >>> gdtrib(1.2, p, 5.6)
  4720. 3.3999999999723882
  4721. """)
  4722. add_newdoc("gdtrix",
  4723. """
  4724. gdtrix(a, b, p, out=None)
  4725. Inverse of `gdtr` vs x.
  4726. Returns the inverse with respect to the parameter `x` of ``p =
  4727. gdtr(a, b, x)``, the cumulative distribution function of the gamma
  4728. distribution. This is also known as the pth quantile of the
  4729. distribution.
  4730. Parameters
  4731. ----------
  4732. a : array_like
  4733. `a` parameter values of `gdtr(a, b, x)`. `1/a` is the "scale"
  4734. parameter of the gamma distribution.
  4735. b : array_like
  4736. `b` parameter values of `gdtr(a, b, x)`. `b` is the "shape" parameter
  4737. of the gamma distribution.
  4738. p : array_like
  4739. Probability values.
  4740. out : ndarray, optional
  4741. If a fourth argument is given, it must be a numpy.ndarray whose size
  4742. matches the broadcast result of `a`, `b` and `x`. `out` is then the
  4743. array returned by the function.
  4744. Returns
  4745. -------
  4746. x : scalar or ndarray
  4747. Values of the `x` parameter such that `p = gdtr(a, b, x)`.
  4748. See Also
  4749. --------
  4750. gdtr : CDF of the gamma distribution.
  4751. gdtria : Inverse with respect to `a` of `gdtr(a, b, x)`.
  4752. gdtrib : Inverse with respect to `b` of `gdtr(a, b, x)`.
  4753. Notes
  4754. -----
  4755. Wrapper for the CDFLIB [1]_ Fortran routine `cdfgam`.
  4756. The cumulative distribution function `p` is computed using a routine by
  4757. DiDinato and Morris [2]_. Computation of `x` involves a search for a value
  4758. that produces the desired value of `p`. The search relies on the
  4759. monotonicity of `p` with `x`.
  4760. References
  4761. ----------
  4762. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  4763. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  4764. Functions, Inverses, and Other Parameters.
  4765. .. [2] DiDinato, A. R. and Morris, A. H.,
  4766. Computation of the incomplete gamma function ratios and their
  4767. inverse. ACM Trans. Math. Softw. 12 (1986), 377-393.
  4768. Examples
  4769. --------
  4770. First evaluate `gdtr`.
  4771. >>> from scipy.special import gdtr, gdtrix
  4772. >>> p = gdtr(1.2, 3.4, 5.6)
  4773. >>> print(p)
  4774. 0.94378087442
  4775. Verify the inverse.
  4776. >>> gdtrix(1.2, 3.4, p)
  4777. 5.5999999999999996
  4778. """)
  4779. add_newdoc("hankel1",
  4780. r"""
  4781. hankel1(v, z, out=None)
  4782. Hankel function of the first kind
  4783. Parameters
  4784. ----------
  4785. v : array_like
  4786. Order (float).
  4787. z : array_like
  4788. Argument (float or complex).
  4789. out : ndarray, optional
  4790. Optional output array for the function values
  4791. Returns
  4792. -------
  4793. scalar or ndarray
  4794. Values of the Hankel function of the first kind.
  4795. Notes
  4796. -----
  4797. A wrapper for the AMOS [1]_ routine `zbesh`, which carries out the
  4798. computation using the relation,
  4799. .. math:: H^{(1)}_v(z) = \frac{2}{\imath\pi} \exp(-\imath \pi v/2) K_v(z \exp(-\imath\pi/2))
  4800. where :math:`K_v` is the modified Bessel function of the second kind.
  4801. For negative orders, the relation
  4802. .. math:: H^{(1)}_{-v}(z) = H^{(1)}_v(z) \exp(\imath\pi v)
  4803. is used.
  4804. See also
  4805. --------
  4806. hankel1e : ndarray
  4807. This function with leading exponential behavior stripped off.
  4808. References
  4809. ----------
  4810. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  4811. of a Complex Argument and Nonnegative Order",
  4812. http://netlib.org/amos/
  4813. """)
  4814. add_newdoc("hankel1e",
  4815. r"""
  4816. hankel1e(v, z, out=None)
  4817. Exponentially scaled Hankel function of the first kind
  4818. Defined as::
  4819. hankel1e(v, z) = hankel1(v, z) * exp(-1j * z)
  4820. Parameters
  4821. ----------
  4822. v : array_like
  4823. Order (float).
  4824. z : array_like
  4825. Argument (float or complex).
  4826. out : ndarray, optional
  4827. Optional output array for the function values
  4828. Returns
  4829. -------
  4830. scalar or ndarray
  4831. Values of the exponentially scaled Hankel function.
  4832. Notes
  4833. -----
  4834. A wrapper for the AMOS [1]_ routine `zbesh`, which carries out the
  4835. computation using the relation,
  4836. .. math:: H^{(1)}_v(z) = \frac{2}{\imath\pi} \exp(-\imath \pi v/2) K_v(z \exp(-\imath\pi/2))
  4837. where :math:`K_v` is the modified Bessel function of the second kind.
  4838. For negative orders, the relation
  4839. .. math:: H^{(1)}_{-v}(z) = H^{(1)}_v(z) \exp(\imath\pi v)
  4840. is used.
  4841. References
  4842. ----------
  4843. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  4844. of a Complex Argument and Nonnegative Order",
  4845. http://netlib.org/amos/
  4846. """)
  4847. add_newdoc("hankel2",
  4848. r"""
  4849. hankel2(v, z, out=None)
  4850. Hankel function of the second kind
  4851. Parameters
  4852. ----------
  4853. v : array_like
  4854. Order (float).
  4855. z : array_like
  4856. Argument (float or complex).
  4857. out : ndarray, optional
  4858. Optional output array for the function values
  4859. Returns
  4860. -------
  4861. scalar or ndarray
  4862. Values of the Hankel function of the second kind.
  4863. Notes
  4864. -----
  4865. A wrapper for the AMOS [1]_ routine `zbesh`, which carries out the
  4866. computation using the relation,
  4867. .. math:: H^{(2)}_v(z) = -\frac{2}{\imath\pi} \exp(\imath \pi v/2) K_v(z \exp(\imath\pi/2))
  4868. where :math:`K_v` is the modified Bessel function of the second kind.
  4869. For negative orders, the relation
  4870. .. math:: H^{(2)}_{-v}(z) = H^{(2)}_v(z) \exp(-\imath\pi v)
  4871. is used.
  4872. See also
  4873. --------
  4874. hankel2e : this function with leading exponential behavior stripped off.
  4875. References
  4876. ----------
  4877. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  4878. of a Complex Argument and Nonnegative Order",
  4879. http://netlib.org/amos/
  4880. """)
  4881. add_newdoc("hankel2e",
  4882. r"""
  4883. hankel2e(v, z, out=None)
  4884. Exponentially scaled Hankel function of the second kind
  4885. Defined as::
  4886. hankel2e(v, z) = hankel2(v, z) * exp(1j * z)
  4887. Parameters
  4888. ----------
  4889. v : array_like
  4890. Order (float).
  4891. z : array_like
  4892. Argument (float or complex).
  4893. out : ndarray, optional
  4894. Optional output array for the function values
  4895. Returns
  4896. -------
  4897. scalar or ndarray
  4898. Values of the exponentially scaled Hankel function of the second kind.
  4899. Notes
  4900. -----
  4901. A wrapper for the AMOS [1]_ routine `zbesh`, which carries out the
  4902. computation using the relation,
  4903. .. math:: H^{(2)}_v(z) = -\frac{2}{\imath\pi} \exp(\frac{\imath \pi v}{2}) K_v(z exp(\frac{\imath\pi}{2}))
  4904. where :math:`K_v` is the modified Bessel function of the second kind.
  4905. For negative orders, the relation
  4906. .. math:: H^{(2)}_{-v}(z) = H^{(2)}_v(z) \exp(-\imath\pi v)
  4907. is used.
  4908. References
  4909. ----------
  4910. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  4911. of a Complex Argument and Nonnegative Order",
  4912. http://netlib.org/amos/
  4913. """)
  4914. add_newdoc("huber",
  4915. r"""
  4916. huber(delta, r, out=None)
  4917. Huber loss function.
  4918. .. math:: \text{huber}(\delta, r) = \begin{cases} \infty & \delta < 0 \\ \frac{1}{2}r^2 & 0 \le \delta, | r | \le \delta \\ \delta ( |r| - \frac{1}{2}\delta ) & \text{otherwise} \end{cases}
  4919. Parameters
  4920. ----------
  4921. delta : ndarray
  4922. Input array, indicating the quadratic vs. linear loss changepoint.
  4923. r : ndarray
  4924. Input array, possibly representing residuals.
  4925. out : ndarray, optional
  4926. Optional output array for the function values
  4927. Returns
  4928. -------
  4929. scalar or ndarray
  4930. The computed Huber loss function values.
  4931. See also
  4932. --------
  4933. pseudo_huber : smooth approximation of this function
  4934. Notes
  4935. -----
  4936. `huber` is useful as a loss function in robust statistics or machine
  4937. learning to reduce the influence of outliers as compared to the common
  4938. squared error loss, residuals with a magnitude higher than `delta` are
  4939. not squared [1]_.
  4940. Typically, `r` represents residuals, the difference
  4941. between a model prediction and data. Then, for :math:`|r|\leq\delta`,
  4942. `huber` resembles the squared error and for :math:`|r|>\delta` the
  4943. absolute error. This way, the Huber loss often achieves
  4944. a fast convergence in model fitting for small residuals like the squared
  4945. error loss function and still reduces the influence of outliers
  4946. (:math:`|r|>\delta`) like the absolute error loss. As :math:`\delta` is
  4947. the cutoff between squared and absolute error regimes, it has
  4948. to be tuned carefully for each problem. `huber` is also
  4949. convex, making it suitable for gradient based optimization.
  4950. .. versionadded:: 0.15.0
  4951. References
  4952. ----------
  4953. .. [1] Peter Huber. "Robust Estimation of a Location Parameter",
  4954. 1964. Annals of Statistics. 53 (1): 73 - 101.
  4955. Examples
  4956. --------
  4957. Import all necessary modules.
  4958. >>> import numpy as np
  4959. >>> from scipy.special import huber
  4960. >>> import matplotlib.pyplot as plt
  4961. Compute the function for ``delta=1`` at ``r=2``
  4962. >>> huber(1., 2.)
  4963. 1.5
  4964. Compute the function for different `delta` by providing a NumPy array or
  4965. list for `delta`.
  4966. >>> huber([1., 3., 5.], 4.)
  4967. array([3.5, 7.5, 8. ])
  4968. Compute the function at different points by providing a NumPy array or
  4969. list for `r`.
  4970. >>> huber(2., np.array([1., 1.5, 3.]))
  4971. array([0.5 , 1.125, 4. ])
  4972. The function can be calculated for different `delta` and `r` by
  4973. providing arrays for both with compatible shapes for broadcasting.
  4974. >>> r = np.array([1., 2.5, 8., 10.])
  4975. >>> deltas = np.array([[1.], [5.], [9.]])
  4976. >>> print(r.shape, deltas.shape)
  4977. (4,) (3, 1)
  4978. >>> huber(deltas, r)
  4979. array([[ 0.5 , 2. , 7.5 , 9.5 ],
  4980. [ 0.5 , 3.125, 27.5 , 37.5 ],
  4981. [ 0.5 , 3.125, 32. , 49.5 ]])
  4982. Plot the function for different `delta`.
  4983. >>> x = np.linspace(-4, 4, 500)
  4984. >>> deltas = [1, 2, 3]
  4985. >>> linestyles = ["dashed", "dotted", "dashdot"]
  4986. >>> fig, ax = plt.subplots()
  4987. >>> combined_plot_parameters = list(zip(deltas, linestyles))
  4988. >>> for delta, style in combined_plot_parameters:
  4989. ... ax.plot(x, huber(delta, x), label=f"$\delta={delta}$", ls=style)
  4990. >>> ax.legend(loc="upper center")
  4991. >>> ax.set_xlabel("$x$")
  4992. >>> ax.set_title("Huber loss function $h_{\delta}(x)$")
  4993. >>> ax.set_xlim(-4, 4)
  4994. >>> ax.set_ylim(0, 8)
  4995. >>> plt.show()
  4996. """)
  4997. add_newdoc("hyp0f1",
  4998. r"""
  4999. hyp0f1(v, z, out=None)
  5000. Confluent hypergeometric limit function 0F1.
  5001. Parameters
  5002. ----------
  5003. v : array_like
  5004. Real-valued parameter
  5005. z : array_like
  5006. Real- or complex-valued argument
  5007. out : ndarray, optional
  5008. Optional output array for the function results
  5009. Returns
  5010. -------
  5011. scalar or ndarray
  5012. The confluent hypergeometric limit function
  5013. Notes
  5014. -----
  5015. This function is defined as:
  5016. .. math:: _0F_1(v, z) = \sum_{k=0}^{\infty}\frac{z^k}{(v)_k k!}.
  5017. It's also the limit as :math:`q \to \infty` of :math:`_1F_1(q; v; z/q)`,
  5018. and satisfies the differential equation :math:`f''(z) + vf'(z) =
  5019. f(z)`. See [1]_ for more information.
  5020. References
  5021. ----------
  5022. .. [1] Wolfram MathWorld, "Confluent Hypergeometric Limit Function",
  5023. http://mathworld.wolfram.com/ConfluentHypergeometricLimitFunction.html
  5024. Examples
  5025. --------
  5026. >>> import numpy as np
  5027. >>> import scipy.special as sc
  5028. It is one when `z` is zero.
  5029. >>> sc.hyp0f1(1, 0)
  5030. 1.0
  5031. It is the limit of the confluent hypergeometric function as `q`
  5032. goes to infinity.
  5033. >>> q = np.array([1, 10, 100, 1000])
  5034. >>> v = 1
  5035. >>> z = 1
  5036. >>> sc.hyp1f1(q, v, z / q)
  5037. array([2.71828183, 2.31481985, 2.28303778, 2.27992985])
  5038. >>> sc.hyp0f1(v, z)
  5039. 2.2795853023360673
  5040. It is related to Bessel functions.
  5041. >>> n = 1
  5042. >>> x = np.linspace(0, 1, 5)
  5043. >>> sc.jv(n, x)
  5044. array([0. , 0.12402598, 0.24226846, 0.3492436 , 0.44005059])
  5045. >>> (0.5 * x)**n / sc.factorial(n) * sc.hyp0f1(n + 1, -0.25 * x**2)
  5046. array([0. , 0.12402598, 0.24226846, 0.3492436 , 0.44005059])
  5047. """)
  5048. add_newdoc("hyp1f1",
  5049. r"""
  5050. hyp1f1(a, b, x, out=None)
  5051. Confluent hypergeometric function 1F1.
  5052. The confluent hypergeometric function is defined by the series
  5053. .. math::
  5054. {}_1F_1(a; b; x) = \sum_{k = 0}^\infty \frac{(a)_k}{(b)_k k!} x^k.
  5055. See [dlmf]_ for more details. Here :math:`(\cdot)_k` is the
  5056. Pochhammer symbol; see `poch`.
  5057. Parameters
  5058. ----------
  5059. a, b : array_like
  5060. Real parameters
  5061. x : array_like
  5062. Real or complex argument
  5063. out : ndarray, optional
  5064. Optional output array for the function results
  5065. Returns
  5066. -------
  5067. scalar or ndarray
  5068. Values of the confluent hypergeometric function
  5069. See also
  5070. --------
  5071. hyperu : another confluent hypergeometric function
  5072. hyp0f1 : confluent hypergeometric limit function
  5073. hyp2f1 : Gaussian hypergeometric function
  5074. References
  5075. ----------
  5076. .. [dlmf] NIST Digital Library of Mathematical Functions
  5077. https://dlmf.nist.gov/13.2#E2
  5078. Examples
  5079. --------
  5080. >>> import numpy as np
  5081. >>> import scipy.special as sc
  5082. It is one when `x` is zero:
  5083. >>> sc.hyp1f1(0.5, 0.5, 0)
  5084. 1.0
  5085. It is singular when `b` is a nonpositive integer.
  5086. >>> sc.hyp1f1(0.5, -1, 0)
  5087. inf
  5088. It is a polynomial when `a` is a nonpositive integer.
  5089. >>> a, b, x = -1, 0.5, np.array([1.0, 2.0, 3.0, 4.0])
  5090. >>> sc.hyp1f1(a, b, x)
  5091. array([-1., -3., -5., -7.])
  5092. >>> 1 + (a / b) * x
  5093. array([-1., -3., -5., -7.])
  5094. It reduces to the exponential function when `a = b`.
  5095. >>> sc.hyp1f1(2, 2, [1, 2, 3, 4])
  5096. array([ 2.71828183, 7.3890561 , 20.08553692, 54.59815003])
  5097. >>> np.exp([1, 2, 3, 4])
  5098. array([ 2.71828183, 7.3890561 , 20.08553692, 54.59815003])
  5099. """)
  5100. add_newdoc("hyp2f1",
  5101. r"""
  5102. hyp2f1(a, b, c, z, out=None)
  5103. Gauss hypergeometric function 2F1(a, b; c; z)
  5104. Parameters
  5105. ----------
  5106. a, b, c : array_like
  5107. Arguments, should be real-valued.
  5108. z : array_like
  5109. Argument, real or complex.
  5110. out : ndarray, optional
  5111. Optional output array for the function values
  5112. Returns
  5113. -------
  5114. hyp2f1 : scalar or ndarray
  5115. The values of the gaussian hypergeometric function.
  5116. See also
  5117. --------
  5118. hyp0f1 : confluent hypergeometric limit function.
  5119. hyp1f1 : Kummer's (confluent hypergeometric) function.
  5120. Notes
  5121. -----
  5122. This function is defined for :math:`|z| < 1` as
  5123. .. math::
  5124. \mathrm{hyp2f1}(a, b, c, z) = \sum_{n=0}^\infty
  5125. \frac{(a)_n (b)_n}{(c)_n}\frac{z^n}{n!},
  5126. and defined on the rest of the complex z-plane by analytic
  5127. continuation [1]_.
  5128. Here :math:`(\cdot)_n` is the Pochhammer symbol; see `poch`. When
  5129. :math:`n` is an integer the result is a polynomial of degree :math:`n`.
  5130. The implementation for complex values of ``z`` is described in [2]_,
  5131. except for ``z`` in the region defined by
  5132. .. math::
  5133. 0.9 <= \left|z\right| < 1.1,
  5134. \left|1 - z\right| >= 0.9,
  5135. \mathrm{real}(z) >= 0
  5136. in which the implementation follows [4]_.
  5137. References
  5138. ----------
  5139. .. [1] NIST Digital Library of Mathematical Functions
  5140. https://dlmf.nist.gov/15.2
  5141. .. [2] S. Zhang and J.M. Jin, "Computation of Special Functions", Wiley 1996
  5142. .. [3] Cephes Mathematical Functions Library,
  5143. http://www.netlib.org/cephes/
  5144. .. [4] J.L. Lopez and N.M. Temme, "New series expansions of the Gauss
  5145. hypergeometric function", Adv Comput Math 39, 349-365 (2013).
  5146. https://doi.org/10.1007/s10444-012-9283-y
  5147. Examples
  5148. --------
  5149. >>> import numpy as np
  5150. >>> import scipy.special as sc
  5151. It has poles when `c` is a negative integer.
  5152. >>> sc.hyp2f1(1, 1, -2, 1)
  5153. inf
  5154. It is a polynomial when `a` or `b` is a negative integer.
  5155. >>> a, b, c = -1, 1, 1.5
  5156. >>> z = np.linspace(0, 1, 5)
  5157. >>> sc.hyp2f1(a, b, c, z)
  5158. array([1. , 0.83333333, 0.66666667, 0.5 , 0.33333333])
  5159. >>> 1 + a * b * z / c
  5160. array([1. , 0.83333333, 0.66666667, 0.5 , 0.33333333])
  5161. It is symmetric in `a` and `b`.
  5162. >>> a = np.linspace(0, 1, 5)
  5163. >>> b = np.linspace(0, 1, 5)
  5164. >>> sc.hyp2f1(a, b, 1, 0.5)
  5165. array([1. , 1.03997334, 1.1803406 , 1.47074441, 2. ])
  5166. >>> sc.hyp2f1(b, a, 1, 0.5)
  5167. array([1. , 1.03997334, 1.1803406 , 1.47074441, 2. ])
  5168. It contains many other functions as special cases.
  5169. >>> z = 0.5
  5170. >>> sc.hyp2f1(1, 1, 2, z)
  5171. 1.3862943611198901
  5172. >>> -np.log(1 - z) / z
  5173. 1.3862943611198906
  5174. >>> sc.hyp2f1(0.5, 1, 1.5, z**2)
  5175. 1.098612288668109
  5176. >>> np.log((1 + z) / (1 - z)) / (2 * z)
  5177. 1.0986122886681098
  5178. >>> sc.hyp2f1(0.5, 1, 1.5, -z**2)
  5179. 0.9272952180016117
  5180. >>> np.arctan(z) / z
  5181. 0.9272952180016122
  5182. """)
  5183. add_newdoc("hyperu",
  5184. r"""
  5185. hyperu(a, b, x, out=None)
  5186. Confluent hypergeometric function U
  5187. It is defined as the solution to the equation
  5188. .. math::
  5189. x \frac{d^2w}{dx^2} + (b - x) \frac{dw}{dx} - aw = 0
  5190. which satisfies the property
  5191. .. math::
  5192. U(a, b, x) \sim x^{-a}
  5193. as :math:`x \to \infty`. See [dlmf]_ for more details.
  5194. Parameters
  5195. ----------
  5196. a, b : array_like
  5197. Real-valued parameters
  5198. x : array_like
  5199. Real-valued argument
  5200. out : ndarray, optional
  5201. Optional output array for the function values
  5202. Returns
  5203. -------
  5204. scalar or ndarray
  5205. Values of `U`
  5206. References
  5207. ----------
  5208. .. [dlmf] NIST Digital Library of Mathematics Functions
  5209. https://dlmf.nist.gov/13.2#E6
  5210. Examples
  5211. --------
  5212. >>> import numpy as np
  5213. >>> import scipy.special as sc
  5214. It has a branch cut along the negative `x` axis.
  5215. >>> x = np.linspace(-0.1, -10, 5)
  5216. >>> sc.hyperu(1, 1, x)
  5217. array([nan, nan, nan, nan, nan])
  5218. It approaches zero as `x` goes to infinity.
  5219. >>> x = np.array([1, 10, 100])
  5220. >>> sc.hyperu(1, 1, x)
  5221. array([0.59634736, 0.09156333, 0.00990194])
  5222. It satisfies Kummer's transformation.
  5223. >>> a, b, x = 2, 1, 1
  5224. >>> sc.hyperu(a, b, x)
  5225. 0.1926947246463881
  5226. >>> x**(1 - b) * sc.hyperu(a - b + 1, 2 - b, x)
  5227. 0.1926947246463881
  5228. """)
  5229. add_newdoc("i0",
  5230. r"""
  5231. i0(x, out=None)
  5232. Modified Bessel function of order 0.
  5233. Defined as,
  5234. .. math::
  5235. I_0(x) = \sum_{k=0}^\infty \frac{(x^2/4)^k}{(k!)^2} = J_0(\imath x),
  5236. where :math:`J_0` is the Bessel function of the first kind of order 0.
  5237. Parameters
  5238. ----------
  5239. x : array_like
  5240. Argument (float)
  5241. out : ndarray, optional
  5242. Optional output array for the function values
  5243. Returns
  5244. -------
  5245. I : scalar or ndarray
  5246. Value of the modified Bessel function of order 0 at `x`.
  5247. Notes
  5248. -----
  5249. The range is partitioned into the two intervals [0, 8] and (8, infinity).
  5250. Chebyshev polynomial expansions are employed in each interval.
  5251. This function is a wrapper for the Cephes [1]_ routine `i0`.
  5252. See also
  5253. --------
  5254. iv: Modified Bessel function of any order
  5255. i0e: Exponentially scaled modified Bessel function of order 0
  5256. References
  5257. ----------
  5258. .. [1] Cephes Mathematical Functions Library,
  5259. http://www.netlib.org/cephes/
  5260. Examples
  5261. --------
  5262. Calculate the function at one point:
  5263. >>> from scipy.special import i0
  5264. >>> i0(1.)
  5265. 1.2660658777520082
  5266. Calculate at several points:
  5267. >>> import numpy as np
  5268. >>> i0(np.array([-2., 0., 3.5]))
  5269. array([2.2795853 , 1. , 7.37820343])
  5270. Plot the function from -10 to 10.
  5271. >>> import matplotlib.pyplot as plt
  5272. >>> fig, ax = plt.subplots()
  5273. >>> x = np.linspace(-10., 10., 1000)
  5274. >>> y = i0(x)
  5275. >>> ax.plot(x, y)
  5276. >>> plt.show()
  5277. """)
  5278. add_newdoc("i0e",
  5279. """
  5280. i0e(x, out=None)
  5281. Exponentially scaled modified Bessel function of order 0.
  5282. Defined as::
  5283. i0e(x) = exp(-abs(x)) * i0(x).
  5284. Parameters
  5285. ----------
  5286. x : array_like
  5287. Argument (float)
  5288. out : ndarray, optional
  5289. Optional output array for the function values
  5290. Returns
  5291. -------
  5292. I : scalar or ndarray
  5293. Value of the exponentially scaled modified Bessel function of order 0
  5294. at `x`.
  5295. Notes
  5296. -----
  5297. The range is partitioned into the two intervals [0, 8] and (8, infinity).
  5298. Chebyshev polynomial expansions are employed in each interval. The
  5299. polynomial expansions used are the same as those in `i0`, but
  5300. they are not multiplied by the dominant exponential factor.
  5301. This function is a wrapper for the Cephes [1]_ routine `i0e`.
  5302. See also
  5303. --------
  5304. iv: Modified Bessel function of the first kind
  5305. i0: Modified Bessel function of order 0
  5306. References
  5307. ----------
  5308. .. [1] Cephes Mathematical Functions Library,
  5309. http://www.netlib.org/cephes/
  5310. Examples
  5311. --------
  5312. Calculate the function at one point:
  5313. >>> from scipy.special import i0e
  5314. >>> i0e(1.)
  5315. 0.46575960759364043
  5316. Calculate the function at several points:
  5317. >>> import numpy as np
  5318. >>> i0e(np.array([-2., 0., 3.]))
  5319. array([0.30850832, 1. , 0.24300035])
  5320. Plot the function from -10 to 10.
  5321. >>> import matplotlib.pyplot as plt
  5322. >>> fig, ax = plt.subplots()
  5323. >>> x = np.linspace(-10., 10., 1000)
  5324. >>> y = i0e(x)
  5325. >>> ax.plot(x, y)
  5326. >>> plt.show()
  5327. Exponentially scaled Bessel functions are useful for large arguments for
  5328. which the unscaled Bessel functions overflow or lose precision. In the
  5329. following example `i0` returns infinity whereas `i0e` still returns
  5330. a finite number.
  5331. >>> from scipy.special import i0
  5332. >>> i0(1000.), i0e(1000.)
  5333. (inf, 0.012617240455891257)
  5334. """)
  5335. add_newdoc("i1",
  5336. r"""
  5337. i1(x, out=None)
  5338. Modified Bessel function of order 1.
  5339. Defined as,
  5340. .. math::
  5341. I_1(x) = \frac{1}{2}x \sum_{k=0}^\infty \frac{(x^2/4)^k}{k! (k + 1)!}
  5342. = -\imath J_1(\imath x),
  5343. where :math:`J_1` is the Bessel function of the first kind of order 1.
  5344. Parameters
  5345. ----------
  5346. x : array_like
  5347. Argument (float)
  5348. out : ndarray, optional
  5349. Optional output array for the function values
  5350. Returns
  5351. -------
  5352. I : scalar or ndarray
  5353. Value of the modified Bessel function of order 1 at `x`.
  5354. Notes
  5355. -----
  5356. The range is partitioned into the two intervals [0, 8] and (8, infinity).
  5357. Chebyshev polynomial expansions are employed in each interval.
  5358. This function is a wrapper for the Cephes [1]_ routine `i1`.
  5359. See also
  5360. --------
  5361. iv: Modified Bessel function of the first kind
  5362. i1e: Exponentially scaled modified Bessel function of order 1
  5363. References
  5364. ----------
  5365. .. [1] Cephes Mathematical Functions Library,
  5366. http://www.netlib.org/cephes/
  5367. Examples
  5368. --------
  5369. Calculate the function at one point:
  5370. >>> from scipy.special import i1
  5371. >>> i1(1.)
  5372. 0.5651591039924851
  5373. Calculate the function at several points:
  5374. >>> import numpy as np
  5375. >>> i1(np.array([-2., 0., 6.]))
  5376. array([-1.59063685, 0. , 61.34193678])
  5377. Plot the function between -10 and 10.
  5378. >>> import matplotlib.pyplot as plt
  5379. >>> fig, ax = plt.subplots()
  5380. >>> x = np.linspace(-10., 10., 1000)
  5381. >>> y = i1(x)
  5382. >>> ax.plot(x, y)
  5383. >>> plt.show()
  5384. """)
  5385. add_newdoc("i1e",
  5386. """
  5387. i1e(x, out=None)
  5388. Exponentially scaled modified Bessel function of order 1.
  5389. Defined as::
  5390. i1e(x) = exp(-abs(x)) * i1(x)
  5391. Parameters
  5392. ----------
  5393. x : array_like
  5394. Argument (float)
  5395. out : ndarray, optional
  5396. Optional output array for the function values
  5397. Returns
  5398. -------
  5399. I : scalar or ndarray
  5400. Value of the exponentially scaled modified Bessel function of order 1
  5401. at `x`.
  5402. Notes
  5403. -----
  5404. The range is partitioned into the two intervals [0, 8] and (8, infinity).
  5405. Chebyshev polynomial expansions are employed in each interval. The
  5406. polynomial expansions used are the same as those in `i1`, but
  5407. they are not multiplied by the dominant exponential factor.
  5408. This function is a wrapper for the Cephes [1]_ routine `i1e`.
  5409. See also
  5410. --------
  5411. iv: Modified Bessel function of the first kind
  5412. i1: Modified Bessel function of order 1
  5413. References
  5414. ----------
  5415. .. [1] Cephes Mathematical Functions Library,
  5416. http://www.netlib.org/cephes/
  5417. Examples
  5418. --------
  5419. Calculate the function at one point:
  5420. >>> from scipy.special import i1e
  5421. >>> i1e(1.)
  5422. 0.2079104153497085
  5423. Calculate the function at several points:
  5424. >>> import numpy as np
  5425. >>> i1e(np.array([-2., 0., 6.]))
  5426. array([-0.21526929, 0. , 0.15205146])
  5427. Plot the function between -10 and 10.
  5428. >>> import matplotlib.pyplot as plt
  5429. >>> fig, ax = plt.subplots()
  5430. >>> x = np.linspace(-10., 10., 1000)
  5431. >>> y = i1e(x)
  5432. >>> ax.plot(x, y)
  5433. >>> plt.show()
  5434. Exponentially scaled Bessel functions are useful for large arguments for
  5435. which the unscaled Bessel functions overflow or lose precision. In the
  5436. following example `i1` returns infinity whereas `i1e` still returns a
  5437. finite number.
  5438. >>> from scipy.special import i1
  5439. >>> i1(1000.), i1e(1000.)
  5440. (inf, 0.01261093025692863)
  5441. """)
  5442. add_newdoc("_igam_fac",
  5443. """
  5444. Internal function, do not use.
  5445. """)
  5446. add_newdoc("it2i0k0",
  5447. r"""
  5448. it2i0k0(x, out=None)
  5449. Integrals related to modified Bessel functions of order 0.
  5450. Computes the integrals
  5451. .. math::
  5452. \int_0^x \frac{I_0(t) - 1}{t} dt \\
  5453. \int_x^\infty \frac{K_0(t)}{t} dt.
  5454. Parameters
  5455. ----------
  5456. x : array_like
  5457. Values at which to evaluate the integrals.
  5458. out : tuple of ndarrays, optional
  5459. Optional output arrays for the function results.
  5460. Returns
  5461. -------
  5462. ii0 : scalar or ndarray
  5463. The integral for `i0`
  5464. ik0 : scalar or ndarray
  5465. The integral for `k0`
  5466. References
  5467. ----------
  5468. .. [1] S. Zhang and J.M. Jin, "Computation of Special Functions",
  5469. Wiley 1996
  5470. Examples
  5471. --------
  5472. Evaluate the functions at one point.
  5473. >>> from scipy.special import it2i0k0
  5474. >>> int_i, int_k = it2i0k0(1.)
  5475. >>> int_i, int_k
  5476. (0.12897944249456852, 0.2085182909001295)
  5477. Evaluate the functions at several points.
  5478. >>> import numpy as np
  5479. >>> points = np.array([0.5, 1.5, 3.])
  5480. >>> int_i, int_k = it2i0k0(points)
  5481. >>> int_i, int_k
  5482. (array([0.03149527, 0.30187149, 1.50012461]),
  5483. array([0.66575102, 0.0823715 , 0.00823631]))
  5484. Plot the functions from 0 to 5.
  5485. >>> import matplotlib.pyplot as plt
  5486. >>> fig, ax = plt.subplots()
  5487. >>> x = np.linspace(0., 5., 1000)
  5488. >>> int_i, int_k = it2i0k0(x)
  5489. >>> ax.plot(x, int_i, label=r"$\int_0^x \frac{I_0(t)-1}{t}\,dt$")
  5490. >>> ax.plot(x, int_k, label=r"$\int_x^{\infty} \frac{K_0(t)}{t}\,dt$")
  5491. >>> ax.legend()
  5492. >>> ax.set_ylim(0, 10)
  5493. >>> plt.show()
  5494. """)
  5495. add_newdoc("it2j0y0",
  5496. r"""
  5497. it2j0y0(x, out=None)
  5498. Integrals related to Bessel functions of the first kind of order 0.
  5499. Computes the integrals
  5500. .. math::
  5501. \int_0^x \frac{1 - J_0(t)}{t} dt \\
  5502. \int_x^\infty \frac{Y_0(t)}{t} dt.
  5503. For more on :math:`J_0` and :math:`Y_0` see `j0` and `y0`.
  5504. Parameters
  5505. ----------
  5506. x : array_like
  5507. Values at which to evaluate the integrals.
  5508. out : tuple of ndarrays, optional
  5509. Optional output arrays for the function results.
  5510. Returns
  5511. -------
  5512. ij0 : scalar or ndarray
  5513. The integral for `j0`
  5514. iy0 : scalar or ndarray
  5515. The integral for `y0`
  5516. References
  5517. ----------
  5518. .. [1] S. Zhang and J.M. Jin, "Computation of Special Functions",
  5519. Wiley 1996
  5520. Examples
  5521. --------
  5522. Evaluate the functions at one point.
  5523. >>> from scipy.special import it2j0y0
  5524. >>> int_j, int_y = it2j0y0(1.)
  5525. >>> int_j, int_y
  5526. (0.12116524699506871, 0.39527290169929336)
  5527. Evaluate the functions at several points.
  5528. >>> import numpy as np
  5529. >>> points = np.array([0.5, 1.5, 3.])
  5530. >>> int_j, int_y = it2j0y0(points)
  5531. >>> int_j, int_y
  5532. (array([0.03100699, 0.26227724, 0.85614669]),
  5533. array([ 0.26968854, 0.29769696, -0.02987272]))
  5534. Plot the functions from 0 to 10.
  5535. >>> import matplotlib.pyplot as plt
  5536. >>> fig, ax = plt.subplots()
  5537. >>> x = np.linspace(0., 10., 1000)
  5538. >>> int_j, int_y = it2j0y0(x)
  5539. >>> ax.plot(x, int_j, label=r"$\int_0^x \frac{1-J_0(t)}{t}\,dt$")
  5540. >>> ax.plot(x, int_y, label=r"$\int_x^{\infty} \frac{Y_0(t)}{t}\,dt$")
  5541. >>> ax.legend()
  5542. >>> ax.set_ylim(-2.5, 2.5)
  5543. >>> plt.show()
  5544. """)
  5545. add_newdoc("it2struve0",
  5546. r"""
  5547. it2struve0(x, out=None)
  5548. Integral related to the Struve function of order 0.
  5549. Returns the integral,
  5550. .. math::
  5551. \int_x^\infty \frac{H_0(t)}{t}\,dt
  5552. where :math:`H_0` is the Struve function of order 0.
  5553. Parameters
  5554. ----------
  5555. x : array_like
  5556. Lower limit of integration.
  5557. out : ndarray, optional
  5558. Optional output array for the function values
  5559. Returns
  5560. -------
  5561. I : scalar or ndarray
  5562. The value of the integral.
  5563. See also
  5564. --------
  5565. struve
  5566. Notes
  5567. -----
  5568. Wrapper for a Fortran routine created by Shanjie Zhang and Jianming
  5569. Jin [1]_.
  5570. References
  5571. ----------
  5572. .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
  5573. Functions", John Wiley and Sons, 1996.
  5574. https://people.sc.fsu.edu/~jburkardt/f_src/special_functions/special_functions.html
  5575. Examples
  5576. --------
  5577. Evaluate the function at one point.
  5578. >>> import numpy as np
  5579. >>> from scipy.special import it2struve0
  5580. >>> it2struve0(1.)
  5581. 0.9571973506383524
  5582. Evaluate the function at several points by supplying
  5583. an array for `x`.
  5584. >>> points = np.array([1., 2., 3.5])
  5585. >>> it2struve0(points)
  5586. array([0.95719735, 0.46909296, 0.10366042])
  5587. Plot the function from -10 to 10.
  5588. >>> import matplotlib.pyplot as plt
  5589. >>> x = np.linspace(-10., 10., 1000)
  5590. >>> it2struve0_values = it2struve0(x)
  5591. >>> fig, ax = plt.subplots()
  5592. >>> ax.plot(x, it2struve0_values)
  5593. >>> ax.set_xlabel(r'$x$')
  5594. >>> ax.set_ylabel(r'$\int_x^{\infty}\frac{H_0(t)}{t}\,dt$')
  5595. >>> plt.show()
  5596. """)
  5597. add_newdoc(
  5598. "itairy",
  5599. r"""
  5600. itairy(x, out=None)
  5601. Integrals of Airy functions
  5602. Calculates the integrals of Airy functions from 0 to `x`.
  5603. Parameters
  5604. ----------
  5605. x : array_like
  5606. Upper limit of integration (float).
  5607. out : tuple of ndarray, optional
  5608. Optional output arrays for the function values
  5609. Returns
  5610. -------
  5611. Apt : scalar or ndarray
  5612. Integral of Ai(t) from 0 to x.
  5613. Bpt : scalar or ndarray
  5614. Integral of Bi(t) from 0 to x.
  5615. Ant : scalar or ndarray
  5616. Integral of Ai(-t) from 0 to x.
  5617. Bnt : scalar or ndarray
  5618. Integral of Bi(-t) from 0 to x.
  5619. Notes
  5620. -----
  5621. Wrapper for a Fortran routine created by Shanjie Zhang and Jianming
  5622. Jin [1]_.
  5623. References
  5624. ----------
  5625. .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
  5626. Functions", John Wiley and Sons, 1996.
  5627. https://people.sc.fsu.edu/~jburkardt/f_src/special_functions/special_functions.html
  5628. Examples
  5629. --------
  5630. Compute the functions at ``x=1.``.
  5631. >>> import numpy as np
  5632. >>> from scipy.special import itairy
  5633. >>> import matplotlib.pyplot as plt
  5634. >>> apt, bpt, ant, bnt = itairy(1.)
  5635. >>> apt, bpt, ant, bnt
  5636. (0.23631734191710949,
  5637. 0.8727691167380077,
  5638. 0.46567398346706845,
  5639. 0.3730050096342943)
  5640. Compute the functions at several points by providing a NumPy array for `x`.
  5641. >>> x = np.array([1., 1.5, 2.5, 5])
  5642. >>> apt, bpt, ant, bnt = itairy(x)
  5643. >>> apt, bpt, ant, bnt
  5644. (array([0.23631734, 0.28678675, 0.324638 , 0.33328759]),
  5645. array([ 0.87276912, 1.62470809, 5.20906691, 321.47831857]),
  5646. array([0.46567398, 0.72232876, 0.93187776, 0.7178822 ]),
  5647. array([ 0.37300501, 0.35038814, -0.02812939, 0.15873094]))
  5648. Plot the functions from -10 to 10.
  5649. >>> x = np.linspace(-10, 10, 500)
  5650. >>> apt, bpt, ant, bnt = itairy(x)
  5651. >>> fig, ax = plt.subplots(figsize=(6, 5))
  5652. >>> ax.plot(x, apt, label="$\int_0^x\, Ai(t)\, dt$")
  5653. >>> ax.plot(x, bpt, ls="dashed", label="$\int_0^x\, Bi(t)\, dt$")
  5654. >>> ax.plot(x, ant, ls="dashdot", label="$\int_0^x\, Ai(-t)\, dt$")
  5655. >>> ax.plot(x, bnt, ls="dotted", label="$\int_0^x\, Bi(-t)\, dt$")
  5656. >>> ax.set_ylim(-2, 1.5)
  5657. >>> ax.legend(loc="lower right")
  5658. >>> plt.show()
  5659. """)
  5660. add_newdoc("iti0k0",
  5661. r"""
  5662. iti0k0(x, out=None)
  5663. Integrals of modified Bessel functions of order 0.
  5664. Computes the integrals
  5665. .. math::
  5666. \int_0^x I_0(t) dt \\
  5667. \int_0^x K_0(t) dt.
  5668. For more on :math:`I_0` and :math:`K_0` see `i0` and `k0`.
  5669. Parameters
  5670. ----------
  5671. x : array_like
  5672. Values at which to evaluate the integrals.
  5673. out : tuple of ndarrays, optional
  5674. Optional output arrays for the function results.
  5675. Returns
  5676. -------
  5677. ii0 : scalar or ndarray
  5678. The integral for `i0`
  5679. ik0 : scalar or ndarray
  5680. The integral for `k0`
  5681. References
  5682. ----------
  5683. .. [1] S. Zhang and J.M. Jin, "Computation of Special Functions",
  5684. Wiley 1996
  5685. Examples
  5686. --------
  5687. Evaluate the functions at one point.
  5688. >>> from scipy.special import iti0k0
  5689. >>> int_i, int_k = iti0k0(1.)
  5690. >>> int_i, int_k
  5691. (1.0865210970235892, 1.2425098486237771)
  5692. Evaluate the functions at several points.
  5693. >>> import numpy as np
  5694. >>> points = np.array([0., 1.5, 3.])
  5695. >>> int_i, int_k = iti0k0(points)
  5696. >>> int_i, int_k
  5697. (array([0. , 1.80606937, 6.16096149]),
  5698. array([0. , 1.39458246, 1.53994809]))
  5699. Plot the functions from 0 to 5.
  5700. >>> import matplotlib.pyplot as plt
  5701. >>> fig, ax = plt.subplots()
  5702. >>> x = np.linspace(0., 5., 1000)
  5703. >>> int_i, int_k = iti0k0(x)
  5704. >>> ax.plot(x, int_i, label="$\int_0^x I_0(t)\,dt$")
  5705. >>> ax.plot(x, int_k, label="$\int_0^x K_0(t)\,dt$")
  5706. >>> ax.legend()
  5707. >>> plt.show()
  5708. """)
  5709. add_newdoc("itj0y0",
  5710. r"""
  5711. itj0y0(x, out=None)
  5712. Integrals of Bessel functions of the first kind of order 0.
  5713. Computes the integrals
  5714. .. math::
  5715. \int_0^x J_0(t) dt \\
  5716. \int_0^x Y_0(t) dt.
  5717. For more on :math:`J_0` and :math:`Y_0` see `j0` and `y0`.
  5718. Parameters
  5719. ----------
  5720. x : array_like
  5721. Values at which to evaluate the integrals.
  5722. out : tuple of ndarrays, optional
  5723. Optional output arrays for the function results.
  5724. Returns
  5725. -------
  5726. ij0 : scalar or ndarray
  5727. The integral of `j0`
  5728. iy0 : scalar or ndarray
  5729. The integral of `y0`
  5730. References
  5731. ----------
  5732. .. [1] S. Zhang and J.M. Jin, "Computation of Special Functions",
  5733. Wiley 1996
  5734. Examples
  5735. --------
  5736. Evaluate the functions at one point.
  5737. >>> from scipy.special import itj0y0
  5738. >>> int_j, int_y = itj0y0(1.)
  5739. >>> int_j, int_y
  5740. (0.9197304100897596, -0.637069376607422)
  5741. Evaluate the functions at several points.
  5742. >>> import numpy as np
  5743. >>> points = np.array([0., 1.5, 3.])
  5744. >>> int_j, int_y = itj0y0(points)
  5745. >>> int_j, int_y
  5746. (array([0. , 1.24144951, 1.38756725]),
  5747. array([ 0. , -0.51175903, 0.19765826]))
  5748. Plot the functions from 0 to 10.
  5749. >>> import matplotlib.pyplot as plt
  5750. >>> fig, ax = plt.subplots()
  5751. >>> x = np.linspace(0., 10., 1000)
  5752. >>> int_j, int_y = itj0y0(x)
  5753. >>> ax.plot(x, int_j, label="$\int_0^x J_0(t)\,dt$")
  5754. >>> ax.plot(x, int_y, label="$\int_0^x Y_0(t)\,dt$")
  5755. >>> ax.legend()
  5756. >>> plt.show()
  5757. """)
  5758. add_newdoc("itmodstruve0",
  5759. r"""
  5760. itmodstruve0(x, out=None)
  5761. Integral of the modified Struve function of order 0.
  5762. .. math::
  5763. I = \int_0^x L_0(t)\,dt
  5764. Parameters
  5765. ----------
  5766. x : array_like
  5767. Upper limit of integration (float).
  5768. out : ndarray, optional
  5769. Optional output array for the function values
  5770. Returns
  5771. -------
  5772. I : scalar or ndarray
  5773. The integral of :math:`L_0` from 0 to `x`.
  5774. Notes
  5775. -----
  5776. Wrapper for a Fortran routine created by Shanjie Zhang and Jianming
  5777. Jin [1]_.
  5778. See Also
  5779. --------
  5780. modstruve: Modified Struve function which is integrated by this function
  5781. References
  5782. ----------
  5783. .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
  5784. Functions", John Wiley and Sons, 1996.
  5785. https://people.sc.fsu.edu/~jburkardt/f_src/special_functions/special_functions.html
  5786. Examples
  5787. --------
  5788. Evaluate the function at one point.
  5789. >>> import numpy as np
  5790. >>> from scipy.special import itmodstruve0
  5791. >>> itmodstruve0(1.)
  5792. 0.3364726286440384
  5793. Evaluate the function at several points by supplying
  5794. an array for `x`.
  5795. >>> points = np.array([1., 2., 3.5])
  5796. >>> itmodstruve0(points)
  5797. array([0.33647263, 1.588285 , 7.60382578])
  5798. Plot the function from -10 to 10.
  5799. >>> import matplotlib.pyplot as plt
  5800. >>> x = np.linspace(-10., 10., 1000)
  5801. >>> itmodstruve0_values = itmodstruve0(x)
  5802. >>> fig, ax = plt.subplots()
  5803. >>> ax.plot(x, itmodstruve0_values)
  5804. >>> ax.set_xlabel(r'$x$')
  5805. >>> ax.set_ylabel(r'$\int_0^xL_0(t)\,dt$')
  5806. >>> plt.show()
  5807. """)
  5808. add_newdoc("itstruve0",
  5809. r"""
  5810. itstruve0(x, out=None)
  5811. Integral of the Struve function of order 0.
  5812. .. math::
  5813. I = \int_0^x H_0(t)\,dt
  5814. Parameters
  5815. ----------
  5816. x : array_like
  5817. Upper limit of integration (float).
  5818. out : ndarray, optional
  5819. Optional output array for the function values
  5820. Returns
  5821. -------
  5822. I : scalar or ndarray
  5823. The integral of :math:`H_0` from 0 to `x`.
  5824. See also
  5825. --------
  5826. struve: Function which is integrated by this function
  5827. Notes
  5828. -----
  5829. Wrapper for a Fortran routine created by Shanjie Zhang and Jianming
  5830. Jin [1]_.
  5831. References
  5832. ----------
  5833. .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
  5834. Functions", John Wiley and Sons, 1996.
  5835. https://people.sc.fsu.edu/~jburkardt/f_src/special_functions/special_functions.html
  5836. Examples
  5837. --------
  5838. Evaluate the function at one point.
  5839. >>> import numpy as np
  5840. >>> from scipy.special import itstruve0
  5841. >>> itstruve0(1.)
  5842. 0.30109042670805547
  5843. Evaluate the function at several points by supplying
  5844. an array for `x`.
  5845. >>> points = np.array([1., 2., 3.5])
  5846. >>> itstruve0(points)
  5847. array([0.30109043, 1.01870116, 1.96804581])
  5848. Plot the function from -20 to 20.
  5849. >>> import matplotlib.pyplot as plt
  5850. >>> x = np.linspace(-20., 20., 1000)
  5851. >>> istruve0_values = itstruve0(x)
  5852. >>> fig, ax = plt.subplots()
  5853. >>> ax.plot(x, istruve0_values)
  5854. >>> ax.set_xlabel(r'$x$')
  5855. >>> ax.set_ylabel(r'$\int_0^{x}H_0(t)\,dt$')
  5856. >>> plt.show()
  5857. """)
  5858. add_newdoc("iv",
  5859. r"""
  5860. iv(v, z, out=None)
  5861. Modified Bessel function of the first kind of real order.
  5862. Parameters
  5863. ----------
  5864. v : array_like
  5865. Order. If `z` is of real type and negative, `v` must be integer
  5866. valued.
  5867. z : array_like of float or complex
  5868. Argument.
  5869. out : ndarray, optional
  5870. Optional output array for the function values
  5871. Returns
  5872. -------
  5873. scalar or ndarray
  5874. Values of the modified Bessel function.
  5875. Notes
  5876. -----
  5877. For real `z` and :math:`v \in [-50, 50]`, the evaluation is carried out
  5878. using Temme's method [1]_. For larger orders, uniform asymptotic
  5879. expansions are applied.
  5880. For complex `z` and positive `v`, the AMOS [2]_ `zbesi` routine is
  5881. called. It uses a power series for small `z`, the asymptotic expansion
  5882. for large `abs(z)`, the Miller algorithm normalized by the Wronskian
  5883. and a Neumann series for intermediate magnitudes, and the uniform
  5884. asymptotic expansions for :math:`I_v(z)` and :math:`J_v(z)` for large
  5885. orders. Backward recurrence is used to generate sequences or reduce
  5886. orders when necessary.
  5887. The calculations above are done in the right half plane and continued
  5888. into the left half plane by the formula,
  5889. .. math:: I_v(z \exp(\pm\imath\pi)) = \exp(\pm\pi v) I_v(z)
  5890. (valid when the real part of `z` is positive). For negative `v`, the
  5891. formula
  5892. .. math:: I_{-v}(z) = I_v(z) + \frac{2}{\pi} \sin(\pi v) K_v(z)
  5893. is used, where :math:`K_v(z)` is the modified Bessel function of the
  5894. second kind, evaluated using the AMOS routine `zbesk`.
  5895. See also
  5896. --------
  5897. ive : This function with leading exponential behavior stripped off.
  5898. i0 : Faster version of this function for order 0.
  5899. i1 : Faster version of this function for order 1.
  5900. References
  5901. ----------
  5902. .. [1] Temme, Journal of Computational Physics, vol 21, 343 (1976)
  5903. .. [2] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  5904. of a Complex Argument and Nonnegative Order",
  5905. http://netlib.org/amos/
  5906. Examples
  5907. --------
  5908. Evaluate the function of order 0 at one point.
  5909. >>> from scipy.special import iv
  5910. >>> iv(0, 1.)
  5911. 1.2660658777520084
  5912. Evaluate the function at one point for different orders.
  5913. >>> iv(0, 1.), iv(1, 1.), iv(1.5, 1.)
  5914. (1.2660658777520084, 0.565159103992485, 0.2935253263474798)
  5915. The evaluation for different orders can be carried out in one call by
  5916. providing a list or NumPy array as argument for the `v` parameter:
  5917. >>> iv([0, 1, 1.5], 1.)
  5918. array([1.26606588, 0.5651591 , 0.29352533])
  5919. Evaluate the function at several points for order 0 by providing an
  5920. array for `z`.
  5921. >>> import numpy as np
  5922. >>> points = np.array([-2., 0., 3.])
  5923. >>> iv(0, points)
  5924. array([2.2795853 , 1. , 4.88079259])
  5925. If `z` is an array, the order parameter `v` must be broadcastable to
  5926. the correct shape if different orders shall be computed in one call.
  5927. To calculate the orders 0 and 1 for an 1D array:
  5928. >>> orders = np.array([[0], [1]])
  5929. >>> orders.shape
  5930. (2, 1)
  5931. >>> iv(orders, points)
  5932. array([[ 2.2795853 , 1. , 4.88079259],
  5933. [-1.59063685, 0. , 3.95337022]])
  5934. Plot the functions of order 0 to 3 from -5 to 5.
  5935. >>> import matplotlib.pyplot as plt
  5936. >>> fig, ax = plt.subplots()
  5937. >>> x = np.linspace(-5., 5., 1000)
  5938. >>> for i in range(4):
  5939. ... ax.plot(x, iv(i, x), label=f'$I_{i!r}$')
  5940. >>> ax.legend()
  5941. >>> plt.show()
  5942. """)
  5943. add_newdoc("ive",
  5944. r"""
  5945. ive(v, z, out=None)
  5946. Exponentially scaled modified Bessel function of the first kind.
  5947. Defined as::
  5948. ive(v, z) = iv(v, z) * exp(-abs(z.real))
  5949. For imaginary numbers without a real part, returns the unscaled
  5950. Bessel function of the first kind `iv`.
  5951. Parameters
  5952. ----------
  5953. v : array_like of float
  5954. Order.
  5955. z : array_like of float or complex
  5956. Argument.
  5957. out : ndarray, optional
  5958. Optional output array for the function values
  5959. Returns
  5960. -------
  5961. scalar or ndarray
  5962. Values of the exponentially scaled modified Bessel function.
  5963. Notes
  5964. -----
  5965. For positive `v`, the AMOS [1]_ `zbesi` routine is called. It uses a
  5966. power series for small `z`, the asymptotic expansion for large
  5967. `abs(z)`, the Miller algorithm normalized by the Wronskian and a
  5968. Neumann series for intermediate magnitudes, and the uniform asymptotic
  5969. expansions for :math:`I_v(z)` and :math:`J_v(z)` for large orders.
  5970. Backward recurrence is used to generate sequences or reduce orders when
  5971. necessary.
  5972. The calculations above are done in the right half plane and continued
  5973. into the left half plane by the formula,
  5974. .. math:: I_v(z \exp(\pm\imath\pi)) = \exp(\pm\pi v) I_v(z)
  5975. (valid when the real part of `z` is positive). For negative `v`, the
  5976. formula
  5977. .. math:: I_{-v}(z) = I_v(z) + \frac{2}{\pi} \sin(\pi v) K_v(z)
  5978. is used, where :math:`K_v(z)` is the modified Bessel function of the
  5979. second kind, evaluated using the AMOS routine `zbesk`.
  5980. See also
  5981. --------
  5982. iv: Modified Bessel function of the first kind
  5983. i0e: Faster implementation of this function for order 0
  5984. i1e: Faster implementation of this function for order 1
  5985. References
  5986. ----------
  5987. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  5988. of a Complex Argument and Nonnegative Order",
  5989. http://netlib.org/amos/
  5990. Examples
  5991. --------
  5992. Evaluate the function of order 0 at one point.
  5993. >>> import numpy as np
  5994. >>> from scipy.special import iv, ive
  5995. >>> import matplotlib.pyplot as plt
  5996. >>> ive(0, 1.)
  5997. 0.4657596075936404
  5998. Evaluate the function at one point for different orders by
  5999. providing a list or NumPy array as argument for the `v` parameter:
  6000. >>> ive([0, 1, 1.5], 1.)
  6001. array([0.46575961, 0.20791042, 0.10798193])
  6002. Evaluate the function at several points for order 0 by providing an
  6003. array for `z`.
  6004. >>> points = np.array([-2., 0., 3.])
  6005. >>> ive(0, points)
  6006. array([0.30850832, 1. , 0.24300035])
  6007. Evaluate the function at several points for different orders by
  6008. providing arrays for both `v` for `z`. Both arrays have to be
  6009. broadcastable to the correct shape. To calculate the orders 0, 1
  6010. and 2 for a 1D array of points:
  6011. >>> ive([[0], [1], [2]], points)
  6012. array([[ 0.30850832, 1. , 0.24300035],
  6013. [-0.21526929, 0. , 0.19682671],
  6014. [ 0.09323903, 0. , 0.11178255]])
  6015. Plot the functions of order 0 to 3 from -5 to 5.
  6016. >>> fig, ax = plt.subplots()
  6017. >>> x = np.linspace(-5., 5., 1000)
  6018. >>> for i in range(4):
  6019. ... ax.plot(x, ive(i, x), label=f'$I_{i!r}(z)\cdot e^{{-|z|}}$')
  6020. >>> ax.legend()
  6021. >>> ax.set_xlabel(r"$z$")
  6022. >>> plt.show()
  6023. Exponentially scaled Bessel functions are useful for large arguments for
  6024. which the unscaled Bessel functions over- or underflow. In the
  6025. following example `iv` returns infinity whereas `ive` still returns
  6026. a finite number.
  6027. >>> iv(3, 1000.), ive(3, 1000.)
  6028. (inf, 0.01256056218254712)
  6029. """)
  6030. add_newdoc("j0",
  6031. r"""
  6032. j0(x, out=None)
  6033. Bessel function of the first kind of order 0.
  6034. Parameters
  6035. ----------
  6036. x : array_like
  6037. Argument (float).
  6038. out : ndarray, optional
  6039. Optional output array for the function values
  6040. Returns
  6041. -------
  6042. J : scalar or ndarray
  6043. Value of the Bessel function of the first kind of order 0 at `x`.
  6044. Notes
  6045. -----
  6046. The domain is divided into the intervals [0, 5] and (5, infinity). In the
  6047. first interval the following rational approximation is used:
  6048. .. math::
  6049. J_0(x) \approx (w - r_1^2)(w - r_2^2) \frac{P_3(w)}{Q_8(w)},
  6050. where :math:`w = x^2` and :math:`r_1`, :math:`r_2` are the zeros of
  6051. :math:`J_0`, and :math:`P_3` and :math:`Q_8` are polynomials of degrees 3
  6052. and 8, respectively.
  6053. In the second interval, the Hankel asymptotic expansion is employed with
  6054. two rational functions of degree 6/6 and 7/7.
  6055. This function is a wrapper for the Cephes [1]_ routine `j0`.
  6056. It should not be confused with the spherical Bessel functions (see
  6057. `spherical_jn`).
  6058. See also
  6059. --------
  6060. jv : Bessel function of real order and complex argument.
  6061. spherical_jn : spherical Bessel functions.
  6062. References
  6063. ----------
  6064. .. [1] Cephes Mathematical Functions Library,
  6065. http://www.netlib.org/cephes/
  6066. Examples
  6067. --------
  6068. Calculate the function at one point:
  6069. >>> from scipy.special import j0
  6070. >>> j0(1.)
  6071. 0.7651976865579665
  6072. Calculate the function at several points:
  6073. >>> import numpy as np
  6074. >>> j0(np.array([-2., 0., 4.]))
  6075. array([ 0.22389078, 1. , -0.39714981])
  6076. Plot the function from -20 to 20.
  6077. >>> import matplotlib.pyplot as plt
  6078. >>> fig, ax = plt.subplots()
  6079. >>> x = np.linspace(-20., 20., 1000)
  6080. >>> y = j0(x)
  6081. >>> ax.plot(x, y)
  6082. >>> plt.show()
  6083. """)
  6084. add_newdoc("j1",
  6085. """
  6086. j1(x, out=None)
  6087. Bessel function of the first kind of order 1.
  6088. Parameters
  6089. ----------
  6090. x : array_like
  6091. Argument (float).
  6092. out : ndarray, optional
  6093. Optional output array for the function values
  6094. Returns
  6095. -------
  6096. J : scalar or ndarray
  6097. Value of the Bessel function of the first kind of order 1 at `x`.
  6098. Notes
  6099. -----
  6100. The domain is divided into the intervals [0, 8] and (8, infinity). In the
  6101. first interval a 24 term Chebyshev expansion is used. In the second, the
  6102. asymptotic trigonometric representation is employed using two rational
  6103. functions of degree 5/5.
  6104. This function is a wrapper for the Cephes [1]_ routine `j1`.
  6105. It should not be confused with the spherical Bessel functions (see
  6106. `spherical_jn`).
  6107. See also
  6108. --------
  6109. jv: Bessel function of the first kind
  6110. spherical_jn: spherical Bessel functions.
  6111. References
  6112. ----------
  6113. .. [1] Cephes Mathematical Functions Library,
  6114. http://www.netlib.org/cephes/
  6115. Examples
  6116. --------
  6117. Calculate the function at one point:
  6118. >>> from scipy.special import j1
  6119. >>> j1(1.)
  6120. 0.44005058574493355
  6121. Calculate the function at several points:
  6122. >>> import numpy as np
  6123. >>> j1(np.array([-2., 0., 4.]))
  6124. array([-0.57672481, 0. , -0.06604333])
  6125. Plot the function from -20 to 20.
  6126. >>> import matplotlib.pyplot as plt
  6127. >>> fig, ax = plt.subplots()
  6128. >>> x = np.linspace(-20., 20., 1000)
  6129. >>> y = j1(x)
  6130. >>> ax.plot(x, y)
  6131. >>> plt.show()
  6132. """)
  6133. add_newdoc("jn",
  6134. """
  6135. jn(n, x, out=None)
  6136. Bessel function of the first kind of integer order and real argument.
  6137. Parameters
  6138. ----------
  6139. n : array_like
  6140. order of the Bessel function
  6141. x : array_like
  6142. argument of the Bessel function
  6143. out : ndarray, optional
  6144. Optional output array for the function values
  6145. Returns
  6146. -------
  6147. scalar or ndarray
  6148. The value of the bessel function
  6149. See also
  6150. --------
  6151. jv
  6152. spherical_jn : spherical Bessel functions.
  6153. Notes
  6154. -----
  6155. `jn` is an alias of `jv`.
  6156. Not to be confused with the spherical Bessel functions (see
  6157. `spherical_jn`).
  6158. """)
  6159. add_newdoc("jv",
  6160. r"""
  6161. jv(v, z, out=None)
  6162. Bessel function of the first kind of real order and complex argument.
  6163. Parameters
  6164. ----------
  6165. v : array_like
  6166. Order (float).
  6167. z : array_like
  6168. Argument (float or complex).
  6169. out : ndarray, optional
  6170. Optional output array for the function values
  6171. Returns
  6172. -------
  6173. J : scalar or ndarray
  6174. Value of the Bessel function, :math:`J_v(z)`.
  6175. See also
  6176. --------
  6177. jve : :math:`J_v` with leading exponential behavior stripped off.
  6178. spherical_jn : spherical Bessel functions.
  6179. j0 : faster version of this function for order 0.
  6180. j1 : faster version of this function for order 1.
  6181. Notes
  6182. -----
  6183. For positive `v` values, the computation is carried out using the AMOS
  6184. [1]_ `zbesj` routine, which exploits the connection to the modified
  6185. Bessel function :math:`I_v`,
  6186. .. math::
  6187. J_v(z) = \exp(v\pi\imath/2) I_v(-\imath z)\qquad (\Im z > 0)
  6188. J_v(z) = \exp(-v\pi\imath/2) I_v(\imath z)\qquad (\Im z < 0)
  6189. For negative `v` values the formula,
  6190. .. math:: J_{-v}(z) = J_v(z) \cos(\pi v) - Y_v(z) \sin(\pi v)
  6191. is used, where :math:`Y_v(z)` is the Bessel function of the second
  6192. kind, computed using the AMOS routine `zbesy`. Note that the second
  6193. term is exactly zero for integer `v`; to improve accuracy the second
  6194. term is explicitly omitted for `v` values such that `v = floor(v)`.
  6195. Not to be confused with the spherical Bessel functions (see `spherical_jn`).
  6196. References
  6197. ----------
  6198. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  6199. of a Complex Argument and Nonnegative Order",
  6200. http://netlib.org/amos/
  6201. Examples
  6202. --------
  6203. Evaluate the function of order 0 at one point.
  6204. >>> from scipy.special import jv
  6205. >>> jv(0, 1.)
  6206. 0.7651976865579666
  6207. Evaluate the function at one point for different orders.
  6208. >>> jv(0, 1.), jv(1, 1.), jv(1.5, 1.)
  6209. (0.7651976865579666, 0.44005058574493355, 0.24029783912342725)
  6210. The evaluation for different orders can be carried out in one call by
  6211. providing a list or NumPy array as argument for the `v` parameter:
  6212. >>> jv([0, 1, 1.5], 1.)
  6213. array([0.76519769, 0.44005059, 0.24029784])
  6214. Evaluate the function at several points for order 0 by providing an
  6215. array for `z`.
  6216. >>> import numpy as np
  6217. >>> points = np.array([-2., 0., 3.])
  6218. >>> jv(0, points)
  6219. array([ 0.22389078, 1. , -0.26005195])
  6220. If `z` is an array, the order parameter `v` must be broadcastable to
  6221. the correct shape if different orders shall be computed in one call.
  6222. To calculate the orders 0 and 1 for an 1D array:
  6223. >>> orders = np.array([[0], [1]])
  6224. >>> orders.shape
  6225. (2, 1)
  6226. >>> jv(orders, points)
  6227. array([[ 0.22389078, 1. , -0.26005195],
  6228. [-0.57672481, 0. , 0.33905896]])
  6229. Plot the functions of order 0 to 3 from -10 to 10.
  6230. >>> import matplotlib.pyplot as plt
  6231. >>> fig, ax = plt.subplots()
  6232. >>> x = np.linspace(-10., 10., 1000)
  6233. >>> for i in range(4):
  6234. ... ax.plot(x, jv(i, x), label=f'$J_{i!r}$')
  6235. >>> ax.legend()
  6236. >>> plt.show()
  6237. """)
  6238. add_newdoc("jve",
  6239. r"""
  6240. jve(v, z, out=None)
  6241. Exponentially scaled Bessel function of the first kind of order `v`.
  6242. Defined as::
  6243. jve(v, z) = jv(v, z) * exp(-abs(z.imag))
  6244. Parameters
  6245. ----------
  6246. v : array_like
  6247. Order (float).
  6248. z : array_like
  6249. Argument (float or complex).
  6250. out : ndarray, optional
  6251. Optional output array for the function values
  6252. Returns
  6253. -------
  6254. J : scalar or ndarray
  6255. Value of the exponentially scaled Bessel function.
  6256. See also
  6257. --------
  6258. jv: Unscaled Bessel function of the first kind
  6259. Notes
  6260. -----
  6261. For positive `v` values, the computation is carried out using the AMOS
  6262. [1]_ `zbesj` routine, which exploits the connection to the modified
  6263. Bessel function :math:`I_v`,
  6264. .. math::
  6265. J_v(z) = \exp(v\pi\imath/2) I_v(-\imath z)\qquad (\Im z > 0)
  6266. J_v(z) = \exp(-v\pi\imath/2) I_v(\imath z)\qquad (\Im z < 0)
  6267. For negative `v` values the formula,
  6268. .. math:: J_{-v}(z) = J_v(z) \cos(\pi v) - Y_v(z) \sin(\pi v)
  6269. is used, where :math:`Y_v(z)` is the Bessel function of the second
  6270. kind, computed using the AMOS routine `zbesy`. Note that the second
  6271. term is exactly zero for integer `v`; to improve accuracy the second
  6272. term is explicitly omitted for `v` values such that `v = floor(v)`.
  6273. Exponentially scaled Bessel functions are useful for large arguments `z`:
  6274. for these, the unscaled Bessel functions can easily under-or overflow.
  6275. References
  6276. ----------
  6277. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  6278. of a Complex Argument and Nonnegative Order",
  6279. http://netlib.org/amos/
  6280. Examples
  6281. --------
  6282. Compare the output of `jv` and `jve` for large complex arguments for `z`
  6283. by computing their values for order ``v=1`` at ``z=1000j``. We see that
  6284. `jv` overflows but `jve` returns a finite number:
  6285. >>> import numpy as np
  6286. >>> from scipy.special import jv, jve
  6287. >>> v = 1
  6288. >>> z = 1000j
  6289. >>> jv(v, z), jve(v, z)
  6290. ((inf+infj), (7.721967686709077e-19+0.012610930256928629j))
  6291. For real arguments for `z`, `jve` returns the same as `jv`.
  6292. >>> v, z = 1, 1000
  6293. >>> jv(v, z), jve(v, z)
  6294. (0.004728311907089523, 0.004728311907089523)
  6295. The function can be evaluated for several orders at the same time by
  6296. providing a list or NumPy array for `v`:
  6297. >>> jve([1, 3, 5], 1j)
  6298. array([1.27304208e-17+2.07910415e-01j, -4.99352086e-19-8.15530777e-03j,
  6299. 6.11480940e-21+9.98657141e-05j])
  6300. In the same way, the function can be evaluated at several points in one
  6301. call by providing a list or NumPy array for `z`:
  6302. >>> jve(1, np.array([1j, 2j, 3j]))
  6303. array([1.27308412e-17+0.20791042j, 1.31814423e-17+0.21526929j,
  6304. 1.20521602e-17+0.19682671j])
  6305. It is also possible to evaluate several orders at several points
  6306. at the same time by providing arrays for `v` and `z` with
  6307. compatible shapes for broadcasting. Compute `jve` for two different orders
  6308. `v` and three points `z` resulting in a 2x3 array.
  6309. >>> v = np.array([[1], [3]])
  6310. >>> z = np.array([1j, 2j, 3j])
  6311. >>> v.shape, z.shape
  6312. ((2, 1), (3,))
  6313. >>> jve(v, z)
  6314. array([[1.27304208e-17+0.20791042j, 1.31810070e-17+0.21526929j,
  6315. 1.20517622e-17+0.19682671j],
  6316. [-4.99352086e-19-0.00815531j, -1.76289571e-18-0.02879122j,
  6317. -2.92578784e-18-0.04778332j]])
  6318. """)
  6319. add_newdoc("k0",
  6320. r"""
  6321. k0(x, out=None)
  6322. Modified Bessel function of the second kind of order 0, :math:`K_0`.
  6323. This function is also sometimes referred to as the modified Bessel
  6324. function of the third kind of order 0.
  6325. Parameters
  6326. ----------
  6327. x : array_like
  6328. Argument (float).
  6329. out : ndarray, optional
  6330. Optional output array for the function values
  6331. Returns
  6332. -------
  6333. K : scalar or ndarray
  6334. Value of the modified Bessel function :math:`K_0` at `x`.
  6335. Notes
  6336. -----
  6337. The range is partitioned into the two intervals [0, 2] and (2, infinity).
  6338. Chebyshev polynomial expansions are employed in each interval.
  6339. This function is a wrapper for the Cephes [1]_ routine `k0`.
  6340. See also
  6341. --------
  6342. kv: Modified Bessel function of the second kind of any order
  6343. k0e: Exponentially scaled modified Bessel function of the second kind
  6344. References
  6345. ----------
  6346. .. [1] Cephes Mathematical Functions Library,
  6347. http://www.netlib.org/cephes/
  6348. Examples
  6349. --------
  6350. Calculate the function at one point:
  6351. >>> from scipy.special import k0
  6352. >>> k0(1.)
  6353. 0.42102443824070823
  6354. Calculate the function at several points:
  6355. >>> import numpy as np
  6356. >>> k0(np.array([0.5, 2., 3.]))
  6357. array([0.92441907, 0.11389387, 0.0347395 ])
  6358. Plot the function from 0 to 10.
  6359. >>> import matplotlib.pyplot as plt
  6360. >>> fig, ax = plt.subplots()
  6361. >>> x = np.linspace(0., 10., 1000)
  6362. >>> y = k0(x)
  6363. >>> ax.plot(x, y)
  6364. >>> plt.show()
  6365. """)
  6366. add_newdoc("k0e",
  6367. """
  6368. k0e(x, out=None)
  6369. Exponentially scaled modified Bessel function K of order 0
  6370. Defined as::
  6371. k0e(x) = exp(x) * k0(x).
  6372. Parameters
  6373. ----------
  6374. x : array_like
  6375. Argument (float)
  6376. out : ndarray, optional
  6377. Optional output array for the function values
  6378. Returns
  6379. -------
  6380. K : scalar or ndarray
  6381. Value of the exponentially scaled modified Bessel function K of order
  6382. 0 at `x`.
  6383. Notes
  6384. -----
  6385. The range is partitioned into the two intervals [0, 2] and (2, infinity).
  6386. Chebyshev polynomial expansions are employed in each interval.
  6387. This function is a wrapper for the Cephes [1]_ routine `k0e`.
  6388. See also
  6389. --------
  6390. kv: Modified Bessel function of the second kind of any order
  6391. k0: Modified Bessel function of the second kind
  6392. References
  6393. ----------
  6394. .. [1] Cephes Mathematical Functions Library,
  6395. http://www.netlib.org/cephes/
  6396. Examples
  6397. --------
  6398. Calculate the function at one point:
  6399. >>> from scipy.special import k0e
  6400. >>> k0e(1.)
  6401. 1.1444630798068947
  6402. Calculate the function at several points:
  6403. >>> import numpy as np
  6404. >>> k0e(np.array([0.5, 2., 3.]))
  6405. array([1.52410939, 0.84156822, 0.6977616 ])
  6406. Plot the function from 0 to 10.
  6407. >>> import matplotlib.pyplot as plt
  6408. >>> fig, ax = plt.subplots()
  6409. >>> x = np.linspace(0., 10., 1000)
  6410. >>> y = k0e(x)
  6411. >>> ax.plot(x, y)
  6412. >>> plt.show()
  6413. Exponentially scaled Bessel functions are useful for large arguments for
  6414. which the unscaled Bessel functions are not precise enough.
  6415. >>> from scipy.special import k0
  6416. >>> k0(1000.)
  6417. 0.
  6418. While `k0` returns zero, `k0e` still returns a finite number:
  6419. >>> k0e(1000.)
  6420. 0.03962832160075422
  6421. """)
  6422. add_newdoc("k1",
  6423. """
  6424. k1(x, out=None)
  6425. Modified Bessel function of the second kind of order 1, :math:`K_1(x)`.
  6426. Parameters
  6427. ----------
  6428. x : array_like
  6429. Argument (float)
  6430. out : ndarray, optional
  6431. Optional output array for the function values
  6432. Returns
  6433. -------
  6434. K : scalar or ndarray
  6435. Value of the modified Bessel function K of order 1 at `x`.
  6436. Notes
  6437. -----
  6438. The range is partitioned into the two intervals [0, 2] and (2, infinity).
  6439. Chebyshev polynomial expansions are employed in each interval.
  6440. This function is a wrapper for the Cephes [1]_ routine `k1`.
  6441. See also
  6442. --------
  6443. kv: Modified Bessel function of the second kind of any order
  6444. k1e: Exponentially scaled modified Bessel function K of order 1
  6445. References
  6446. ----------
  6447. .. [1] Cephes Mathematical Functions Library,
  6448. http://www.netlib.org/cephes/
  6449. Examples
  6450. --------
  6451. Calculate the function at one point:
  6452. >>> from scipy.special import k1
  6453. >>> k1(1.)
  6454. 0.6019072301972346
  6455. Calculate the function at several points:
  6456. >>> import numpy as np
  6457. >>> k1(np.array([0.5, 2., 3.]))
  6458. array([1.65644112, 0.13986588, 0.04015643])
  6459. Plot the function from 0 to 10.
  6460. >>> import matplotlib.pyplot as plt
  6461. >>> fig, ax = plt.subplots()
  6462. >>> x = np.linspace(0., 10., 1000)
  6463. >>> y = k1(x)
  6464. >>> ax.plot(x, y)
  6465. >>> plt.show()
  6466. """)
  6467. add_newdoc("k1e",
  6468. """
  6469. k1e(x, out=None)
  6470. Exponentially scaled modified Bessel function K of order 1
  6471. Defined as::
  6472. k1e(x) = exp(x) * k1(x)
  6473. Parameters
  6474. ----------
  6475. x : array_like
  6476. Argument (float)
  6477. out : ndarray, optional
  6478. Optional output array for the function values
  6479. Returns
  6480. -------
  6481. K : scalar or ndarray
  6482. Value of the exponentially scaled modified Bessel function K of order
  6483. 1 at `x`.
  6484. Notes
  6485. -----
  6486. The range is partitioned into the two intervals [0, 2] and (2, infinity).
  6487. Chebyshev polynomial expansions are employed in each interval.
  6488. This function is a wrapper for the Cephes [1]_ routine `k1e`.
  6489. See also
  6490. --------
  6491. kv: Modified Bessel function of the second kind of any order
  6492. k1: Modified Bessel function of the second kind of order 1
  6493. References
  6494. ----------
  6495. .. [1] Cephes Mathematical Functions Library,
  6496. http://www.netlib.org/cephes/
  6497. Examples
  6498. --------
  6499. Calculate the function at one point:
  6500. >>> from scipy.special import k1e
  6501. >>> k1e(1.)
  6502. 1.636153486263258
  6503. Calculate the function at several points:
  6504. >>> import numpy as np
  6505. >>> k1e(np.array([0.5, 2., 3.]))
  6506. array([2.73100971, 1.03347685, 0.80656348])
  6507. Plot the function from 0 to 10.
  6508. >>> import matplotlib.pyplot as plt
  6509. >>> fig, ax = plt.subplots()
  6510. >>> x = np.linspace(0., 10., 1000)
  6511. >>> y = k1e(x)
  6512. >>> ax.plot(x, y)
  6513. >>> plt.show()
  6514. Exponentially scaled Bessel functions are useful for large arguments for
  6515. which the unscaled Bessel functions are not precise enough. In the
  6516. following example `k1` returns zero whereas `k1e` still returns a
  6517. useful floating point number.
  6518. >>> from scipy.special import k1
  6519. >>> k1(1000.), k1e(1000.)
  6520. (0., 0.03964813081296021)
  6521. """)
  6522. add_newdoc("kei",
  6523. r"""
  6524. kei(x, out=None)
  6525. Kelvin function kei.
  6526. Defined as
  6527. .. math::
  6528. \mathrm{kei}(x) = \Im[K_0(x e^{\pi i / 4})]
  6529. where :math:`K_0` is the modified Bessel function of the second
  6530. kind (see `kv`). See [dlmf]_ for more details.
  6531. Parameters
  6532. ----------
  6533. x : array_like
  6534. Real argument.
  6535. out : ndarray, optional
  6536. Optional output array for the function results.
  6537. Returns
  6538. -------
  6539. scalar or ndarray
  6540. Values of the Kelvin function.
  6541. See Also
  6542. --------
  6543. ker : the corresponding real part
  6544. keip : the derivative of kei
  6545. kv : modified Bessel function of the second kind
  6546. References
  6547. ----------
  6548. .. [dlmf] NIST, Digital Library of Mathematical Functions,
  6549. https://dlmf.nist.gov/10.61
  6550. Examples
  6551. --------
  6552. It can be expressed using the modified Bessel function of the
  6553. second kind.
  6554. >>> import numpy as np
  6555. >>> import scipy.special as sc
  6556. >>> x = np.array([1.0, 2.0, 3.0, 4.0])
  6557. >>> sc.kv(0, x * np.exp(np.pi * 1j / 4)).imag
  6558. array([-0.49499464, -0.20240007, -0.05112188, 0.0021984 ])
  6559. >>> sc.kei(x)
  6560. array([-0.49499464, -0.20240007, -0.05112188, 0.0021984 ])
  6561. """)
  6562. add_newdoc("keip",
  6563. r"""
  6564. keip(x, out=None)
  6565. Derivative of the Kelvin function kei.
  6566. Parameters
  6567. ----------
  6568. x : array_like
  6569. Real argument.
  6570. out : ndarray, optional
  6571. Optional output array for the function results.
  6572. Returns
  6573. -------
  6574. scalar or ndarray
  6575. The values of the derivative of kei.
  6576. See Also
  6577. --------
  6578. kei
  6579. References
  6580. ----------
  6581. .. [dlmf] NIST, Digital Library of Mathematical Functions,
  6582. https://dlmf.nist.gov/10#PT5
  6583. """)
  6584. add_newdoc("kelvin",
  6585. """
  6586. kelvin(x, out=None)
  6587. Kelvin functions as complex numbers
  6588. Parameters
  6589. ----------
  6590. x : array_like
  6591. Argument
  6592. out : tuple of ndarray, optional
  6593. Optional output arrays for the function values
  6594. Returns
  6595. -------
  6596. Be, Ke, Bep, Kep : 4-tuple of scalar or ndarray
  6597. The tuple (Be, Ke, Bep, Kep) contains complex numbers
  6598. representing the real and imaginary Kelvin functions and their
  6599. derivatives evaluated at `x`. For example, kelvin(x)[0].real =
  6600. ber x and kelvin(x)[0].imag = bei x with similar relationships
  6601. for ker and kei.
  6602. """)
  6603. add_newdoc("ker",
  6604. r"""
  6605. ker(x, out=None)
  6606. Kelvin function ker.
  6607. Defined as
  6608. .. math::
  6609. \mathrm{ker}(x) = \Re[K_0(x e^{\pi i / 4})]
  6610. Where :math:`K_0` is the modified Bessel function of the second
  6611. kind (see `kv`). See [dlmf]_ for more details.
  6612. Parameters
  6613. ----------
  6614. x : array_like
  6615. Real argument.
  6616. out : ndarray, optional
  6617. Optional output array for the function results.
  6618. Returns
  6619. -------
  6620. scalar or ndarray
  6621. Values of the Kelvin function.
  6622. See Also
  6623. --------
  6624. kei : the corresponding imaginary part
  6625. kerp : the derivative of ker
  6626. kv : modified Bessel function of the second kind
  6627. References
  6628. ----------
  6629. .. [dlmf] NIST, Digital Library of Mathematical Functions,
  6630. https://dlmf.nist.gov/10.61
  6631. Examples
  6632. --------
  6633. It can be expressed using the modified Bessel function of the
  6634. second kind.
  6635. >>> import numpy as np
  6636. >>> import scipy.special as sc
  6637. >>> x = np.array([1.0, 2.0, 3.0, 4.0])
  6638. >>> sc.kv(0, x * np.exp(np.pi * 1j / 4)).real
  6639. array([ 0.28670621, -0.04166451, -0.06702923, -0.03617885])
  6640. >>> sc.ker(x)
  6641. array([ 0.28670621, -0.04166451, -0.06702923, -0.03617885])
  6642. """)
  6643. add_newdoc("kerp",
  6644. r"""
  6645. kerp(x, out=None)
  6646. Derivative of the Kelvin function ker.
  6647. Parameters
  6648. ----------
  6649. x : array_like
  6650. Real argument.
  6651. out : ndarray, optional
  6652. Optional output array for the function results.
  6653. Returns
  6654. -------
  6655. scalar or ndarray
  6656. Values of the derivative of ker.
  6657. See Also
  6658. --------
  6659. ker
  6660. References
  6661. ----------
  6662. .. [dlmf] NIST, Digital Library of Mathematical Functions,
  6663. https://dlmf.nist.gov/10#PT5
  6664. """)
  6665. add_newdoc("kl_div",
  6666. r"""
  6667. kl_div(x, y, out=None)
  6668. Elementwise function for computing Kullback-Leibler divergence.
  6669. .. math::
  6670. \mathrm{kl\_div}(x, y) =
  6671. \begin{cases}
  6672. x \log(x / y) - x + y & x > 0, y > 0 \\
  6673. y & x = 0, y \ge 0 \\
  6674. \infty & \text{otherwise}
  6675. \end{cases}
  6676. Parameters
  6677. ----------
  6678. x, y : array_like
  6679. Real arguments
  6680. out : ndarray, optional
  6681. Optional output array for the function results
  6682. Returns
  6683. -------
  6684. scalar or ndarray
  6685. Values of the Kullback-Liebler divergence.
  6686. See Also
  6687. --------
  6688. entr, rel_entr, scipy.stats.entropy
  6689. Notes
  6690. -----
  6691. .. versionadded:: 0.15.0
  6692. This function is non-negative and is jointly convex in `x` and `y`.
  6693. The origin of this function is in convex programming; see [1]_ for
  6694. details. This is why the function contains the extra :math:`-x
  6695. + y` terms over what might be expected from the Kullback-Leibler
  6696. divergence. For a version of the function without the extra terms,
  6697. see `rel_entr`.
  6698. References
  6699. ----------
  6700. .. [1] Boyd, Stephen and Lieven Vandenberghe. *Convex optimization*.
  6701. Cambridge University Press, 2004.
  6702. :doi:`https://doi.org/10.1017/CBO9780511804441`
  6703. """)
  6704. add_newdoc("kn",
  6705. r"""
  6706. kn(n, x, out=None)
  6707. Modified Bessel function of the second kind of integer order `n`
  6708. Returns the modified Bessel function of the second kind for integer order
  6709. `n` at real `z`.
  6710. These are also sometimes called functions of the third kind, Basset
  6711. functions, or Macdonald functions.
  6712. Parameters
  6713. ----------
  6714. n : array_like of int
  6715. Order of Bessel functions (floats will truncate with a warning)
  6716. x : array_like of float
  6717. Argument at which to evaluate the Bessel functions
  6718. out : ndarray, optional
  6719. Optional output array for the function results.
  6720. Returns
  6721. -------
  6722. scalar or ndarray
  6723. Value of the Modified Bessel function of the second kind,
  6724. :math:`K_n(x)`.
  6725. Notes
  6726. -----
  6727. Wrapper for AMOS [1]_ routine `zbesk`. For a discussion of the
  6728. algorithm used, see [2]_ and the references therein.
  6729. See Also
  6730. --------
  6731. kv : Same function, but accepts real order and complex argument
  6732. kvp : Derivative of this function
  6733. References
  6734. ----------
  6735. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  6736. of a Complex Argument and Nonnegative Order",
  6737. http://netlib.org/amos/
  6738. .. [2] Donald E. Amos, "Algorithm 644: A portable package for Bessel
  6739. functions of a complex argument and nonnegative order", ACM
  6740. TOMS Vol. 12 Issue 3, Sept. 1986, p. 265
  6741. Examples
  6742. --------
  6743. Plot the function of several orders for real input:
  6744. >>> import numpy as np
  6745. >>> from scipy.special import kn
  6746. >>> import matplotlib.pyplot as plt
  6747. >>> x = np.linspace(0, 5, 1000)
  6748. >>> for N in range(6):
  6749. ... plt.plot(x, kn(N, x), label='$K_{}(x)$'.format(N))
  6750. >>> plt.ylim(0, 10)
  6751. >>> plt.legend()
  6752. >>> plt.title(r'Modified Bessel function of the second kind $K_n(x)$')
  6753. >>> plt.show()
  6754. Calculate for a single value at multiple orders:
  6755. >>> kn([4, 5, 6], 1)
  6756. array([ 44.23241585, 360.9605896 , 3653.83831186])
  6757. """)
  6758. add_newdoc("kolmogi",
  6759. """
  6760. kolmogi(p, out=None)
  6761. Inverse Survival Function of Kolmogorov distribution
  6762. It is the inverse function to `kolmogorov`.
  6763. Returns y such that ``kolmogorov(y) == p``.
  6764. Parameters
  6765. ----------
  6766. p : float array_like
  6767. Probability
  6768. out : ndarray, optional
  6769. Optional output array for the function results
  6770. Returns
  6771. -------
  6772. scalar or ndarray
  6773. The value(s) of kolmogi(p)
  6774. Notes
  6775. -----
  6776. `kolmogorov` is used by `stats.kstest` in the application of the
  6777. Kolmogorov-Smirnov Goodness of Fit test. For historial reasons this
  6778. function is exposed in `scpy.special`, but the recommended way to achieve
  6779. the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
  6780. `stats.kstwobign` distribution.
  6781. See Also
  6782. --------
  6783. kolmogorov : The Survival Function for the distribution
  6784. scipy.stats.kstwobign : Provides the functionality as a continuous distribution
  6785. smirnov, smirnovi : Functions for the one-sided distribution
  6786. Examples
  6787. --------
  6788. >>> from scipy.special import kolmogi
  6789. >>> kolmogi([0, 0.1, 0.25, 0.5, 0.75, 0.9, 1.0])
  6790. array([ inf, 1.22384787, 1.01918472, 0.82757356, 0.67644769,
  6791. 0.57117327, 0. ])
  6792. """)
  6793. add_newdoc("kolmogorov",
  6794. r"""
  6795. kolmogorov(y, out=None)
  6796. Complementary cumulative distribution (Survival Function) function of
  6797. Kolmogorov distribution.
  6798. Returns the complementary cumulative distribution function of
  6799. Kolmogorov's limiting distribution (``D_n*\sqrt(n)`` as n goes to infinity)
  6800. of a two-sided test for equality between an empirical and a theoretical
  6801. distribution. It is equal to the (limit as n->infinity of the)
  6802. probability that ``sqrt(n) * max absolute deviation > y``.
  6803. Parameters
  6804. ----------
  6805. y : float array_like
  6806. Absolute deviation between the Empirical CDF (ECDF) and the target CDF,
  6807. multiplied by sqrt(n).
  6808. out : ndarray, optional
  6809. Optional output array for the function results
  6810. Returns
  6811. -------
  6812. scalar or ndarray
  6813. The value(s) of kolmogorov(y)
  6814. Notes
  6815. -----
  6816. `kolmogorov` is used by `stats.kstest` in the application of the
  6817. Kolmogorov-Smirnov Goodness of Fit test. For historial reasons this
  6818. function is exposed in `scpy.special`, but the recommended way to achieve
  6819. the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
  6820. `stats.kstwobign` distribution.
  6821. See Also
  6822. --------
  6823. kolmogi : The Inverse Survival Function for the distribution
  6824. scipy.stats.kstwobign : Provides the functionality as a continuous distribution
  6825. smirnov, smirnovi : Functions for the one-sided distribution
  6826. Examples
  6827. --------
  6828. Show the probability of a gap at least as big as 0, 0.5 and 1.0.
  6829. >>> import numpy as np
  6830. >>> from scipy.special import kolmogorov
  6831. >>> from scipy.stats import kstwobign
  6832. >>> kolmogorov([0, 0.5, 1.0])
  6833. array([ 1. , 0.96394524, 0.26999967])
  6834. Compare a sample of size 1000 drawn from a Laplace(0, 1) distribution against
  6835. the target distribution, a Normal(0, 1) distribution.
  6836. >>> from scipy.stats import norm, laplace
  6837. >>> rng = np.random.default_rng()
  6838. >>> n = 1000
  6839. >>> lap01 = laplace(0, 1)
  6840. >>> x = np.sort(lap01.rvs(n, random_state=rng))
  6841. >>> np.mean(x), np.std(x)
  6842. (-0.05841730131499543, 1.3968109101997568)
  6843. Construct the Empirical CDF and the K-S statistic Dn.
  6844. >>> target = norm(0,1) # Normal mean 0, stddev 1
  6845. >>> cdfs = target.cdf(x)
  6846. >>> ecdfs = np.arange(n+1, dtype=float)/n
  6847. >>> gaps = np.column_stack([cdfs - ecdfs[:n], ecdfs[1:] - cdfs])
  6848. >>> Dn = np.max(gaps)
  6849. >>> Kn = np.sqrt(n) * Dn
  6850. >>> print('Dn=%f, sqrt(n)*Dn=%f' % (Dn, Kn))
  6851. Dn=0.043363, sqrt(n)*Dn=1.371265
  6852. >>> print(chr(10).join(['For a sample of size n drawn from a N(0, 1) distribution:',
  6853. ... ' the approximate Kolmogorov probability that sqrt(n)*Dn>=%f is %f' % (Kn, kolmogorov(Kn)),
  6854. ... ' the approximate Kolmogorov probability that sqrt(n)*Dn<=%f is %f' % (Kn, kstwobign.cdf(Kn))]))
  6855. For a sample of size n drawn from a N(0, 1) distribution:
  6856. the approximate Kolmogorov probability that sqrt(n)*Dn>=1.371265 is 0.046533
  6857. the approximate Kolmogorov probability that sqrt(n)*Dn<=1.371265 is 0.953467
  6858. Plot the Empirical CDF against the target N(0, 1) CDF.
  6859. >>> import matplotlib.pyplot as plt
  6860. >>> plt.step(np.concatenate([[-3], x]), ecdfs, where='post', label='Empirical CDF')
  6861. >>> x3 = np.linspace(-3, 3, 100)
  6862. >>> plt.plot(x3, target.cdf(x3), label='CDF for N(0, 1)')
  6863. >>> plt.ylim([0, 1]); plt.grid(True); plt.legend();
  6864. >>> # Add vertical lines marking Dn+ and Dn-
  6865. >>> iminus, iplus = np.argmax(gaps, axis=0)
  6866. >>> plt.vlines([x[iminus]], ecdfs[iminus], cdfs[iminus], color='r', linestyle='dashed', lw=4)
  6867. >>> plt.vlines([x[iplus]], cdfs[iplus], ecdfs[iplus+1], color='r', linestyle='dashed', lw=4)
  6868. >>> plt.show()
  6869. """)
  6870. add_newdoc("_kolmogc",
  6871. r"""
  6872. Internal function, do not use.
  6873. """)
  6874. add_newdoc("_kolmogci",
  6875. r"""
  6876. Internal function, do not use.
  6877. """)
  6878. add_newdoc("_kolmogp",
  6879. r"""
  6880. Internal function, do not use.
  6881. """)
  6882. add_newdoc("kv",
  6883. r"""
  6884. kv(v, z, out=None)
  6885. Modified Bessel function of the second kind of real order `v`
  6886. Returns the modified Bessel function of the second kind for real order
  6887. `v` at complex `z`.
  6888. These are also sometimes called functions of the third kind, Basset
  6889. functions, or Macdonald functions. They are defined as those solutions
  6890. of the modified Bessel equation for which,
  6891. .. math::
  6892. K_v(x) \sim \sqrt{\pi/(2x)} \exp(-x)
  6893. as :math:`x \to \infty` [3]_.
  6894. Parameters
  6895. ----------
  6896. v : array_like of float
  6897. Order of Bessel functions
  6898. z : array_like of complex
  6899. Argument at which to evaluate the Bessel functions
  6900. out : ndarray, optional
  6901. Optional output array for the function results
  6902. Returns
  6903. -------
  6904. scalar or ndarray
  6905. The results. Note that input must be of complex type to get complex
  6906. output, e.g. ``kv(3, -2+0j)`` instead of ``kv(3, -2)``.
  6907. Notes
  6908. -----
  6909. Wrapper for AMOS [1]_ routine `zbesk`. For a discussion of the
  6910. algorithm used, see [2]_ and the references therein.
  6911. See Also
  6912. --------
  6913. kve : This function with leading exponential behavior stripped off.
  6914. kvp : Derivative of this function
  6915. References
  6916. ----------
  6917. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  6918. of a Complex Argument and Nonnegative Order",
  6919. http://netlib.org/amos/
  6920. .. [2] Donald E. Amos, "Algorithm 644: A portable package for Bessel
  6921. functions of a complex argument and nonnegative order", ACM
  6922. TOMS Vol. 12 Issue 3, Sept. 1986, p. 265
  6923. .. [3] NIST Digital Library of Mathematical Functions,
  6924. Eq. 10.25.E3. https://dlmf.nist.gov/10.25.E3
  6925. Examples
  6926. --------
  6927. Plot the function of several orders for real input:
  6928. >>> import numpy as np
  6929. >>> from scipy.special import kv
  6930. >>> import matplotlib.pyplot as plt
  6931. >>> x = np.linspace(0, 5, 1000)
  6932. >>> for N in np.linspace(0, 6, 5):
  6933. ... plt.plot(x, kv(N, x), label='$K_{{{}}}(x)$'.format(N))
  6934. >>> plt.ylim(0, 10)
  6935. >>> plt.legend()
  6936. >>> plt.title(r'Modified Bessel function of the second kind $K_\nu(x)$')
  6937. >>> plt.show()
  6938. Calculate for a single value at multiple orders:
  6939. >>> kv([4, 4.5, 5], 1+2j)
  6940. array([ 0.1992+2.3892j, 2.3493+3.6j , 7.2827+3.8104j])
  6941. """)
  6942. add_newdoc("kve",
  6943. r"""
  6944. kve(v, z, out=None)
  6945. Exponentially scaled modified Bessel function of the second kind.
  6946. Returns the exponentially scaled, modified Bessel function of the
  6947. second kind (sometimes called the third kind) for real order `v` at
  6948. complex `z`::
  6949. kve(v, z) = kv(v, z) * exp(z)
  6950. Parameters
  6951. ----------
  6952. v : array_like of float
  6953. Order of Bessel functions
  6954. z : array_like of complex
  6955. Argument at which to evaluate the Bessel functions
  6956. out : ndarray, optional
  6957. Optional output array for the function results
  6958. Returns
  6959. -------
  6960. scalar or ndarray
  6961. The exponentially scaled modified Bessel function of the second kind.
  6962. Notes
  6963. -----
  6964. Wrapper for AMOS [1]_ routine `zbesk`. For a discussion of the
  6965. algorithm used, see [2]_ and the references therein.
  6966. See Also
  6967. --------
  6968. kv : This function without exponential scaling.
  6969. k0e : Faster version of this function for order 0.
  6970. k1e : Faster version of this function for order 1.
  6971. References
  6972. ----------
  6973. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  6974. of a Complex Argument and Nonnegative Order",
  6975. http://netlib.org/amos/
  6976. .. [2] Donald E. Amos, "Algorithm 644: A portable package for Bessel
  6977. functions of a complex argument and nonnegative order", ACM
  6978. TOMS Vol. 12 Issue 3, Sept. 1986, p. 265
  6979. Examples
  6980. --------
  6981. Evaluate the function of order 0 at one point.
  6982. >>> import numpy as np
  6983. >>> from scipy.special import kv, kve
  6984. >>> import matplotlib.pyplot as plt
  6985. >>> kve(0, 1.)
  6986. 1.1444630798068949
  6987. Evaluate the function at one point for different orders by
  6988. providing a list or NumPy array as argument for the `v` parameter:
  6989. >>> kve([0, 1, 1.5], 1.)
  6990. array([1.14446308, 1.63615349, 2.50662827])
  6991. Evaluate the function at several points for order 0 by providing an
  6992. array for `z`.
  6993. >>> points = np.array([1., 3., 10.])
  6994. >>> kve(0, points)
  6995. array([1.14446308, 0.6977616 , 0.39163193])
  6996. Evaluate the function at several points for different orders by
  6997. providing arrays for both `v` for `z`. Both arrays have to be
  6998. broadcastable to the correct shape. To calculate the orders 0, 1
  6999. and 2 for a 1D array of points:
  7000. >>> kve([[0], [1], [2]], points)
  7001. array([[1.14446308, 0.6977616 , 0.39163193],
  7002. [1.63615349, 0.80656348, 0.41076657],
  7003. [4.41677005, 1.23547058, 0.47378525]])
  7004. Plot the functions of order 0 to 3 from 0 to 5.
  7005. >>> fig, ax = plt.subplots()
  7006. >>> x = np.linspace(0., 5., 1000)
  7007. >>> for i in range(4):
  7008. ... ax.plot(x, kve(i, x), label=f'$K_{i!r}(z)\cdot e^z$')
  7009. >>> ax.legend()
  7010. >>> ax.set_xlabel(r"$z$")
  7011. >>> ax.set_ylim(0, 4)
  7012. >>> ax.set_xlim(0, 5)
  7013. >>> plt.show()
  7014. Exponentially scaled Bessel functions are useful for large arguments for
  7015. which the unscaled Bessel functions over- or underflow. In the
  7016. following example `kv` returns 0 whereas `kve` still returns
  7017. a useful finite number.
  7018. >>> kv(3, 1000.), kve(3, 1000.)
  7019. (0.0, 0.03980696128440973)
  7020. """)
  7021. add_newdoc("_lanczos_sum_expg_scaled",
  7022. """
  7023. Internal function, do not use.
  7024. """)
  7025. add_newdoc("_lgam1p",
  7026. """
  7027. Internal function, do not use.
  7028. """)
  7029. add_newdoc("log1p",
  7030. """
  7031. log1p(x, out=None)
  7032. Calculates log(1 + x) for use when `x` is near zero.
  7033. Parameters
  7034. ----------
  7035. x : array_like
  7036. Real or complex valued input.
  7037. out : ndarray, optional
  7038. Optional output array for the function results.
  7039. Returns
  7040. -------
  7041. scalar or ndarray
  7042. Values of ``log(1 + x)``.
  7043. See Also
  7044. --------
  7045. expm1, cosm1
  7046. Examples
  7047. --------
  7048. >>> import numpy as np
  7049. >>> import scipy.special as sc
  7050. It is more accurate than using ``log(1 + x)`` directly for ``x``
  7051. near 0. Note that in the below example ``1 + 1e-17 == 1`` to
  7052. double precision.
  7053. >>> sc.log1p(1e-17)
  7054. 1e-17
  7055. >>> np.log(1 + 1e-17)
  7056. 0.0
  7057. """)
  7058. add_newdoc("_log1pmx",
  7059. """
  7060. Internal function, do not use.
  7061. """)
  7062. add_newdoc('log_expit',
  7063. """
  7064. log_expit(x, out=None)
  7065. Logarithm of the logistic sigmoid function.
  7066. The SciPy implementation of the logistic sigmoid function is
  7067. `scipy.special.expit`, so this function is called ``log_expit``.
  7068. The function is mathematically equivalent to ``log(expit(x))``, but
  7069. is formulated to avoid loss of precision for inputs with large
  7070. (positive or negative) magnitude.
  7071. Parameters
  7072. ----------
  7073. x : array_like
  7074. The values to apply ``log_expit`` to element-wise.
  7075. out : ndarray, optional
  7076. Optional output array for the function results
  7077. Returns
  7078. -------
  7079. out : scalar or ndarray
  7080. The computed values, an ndarray of the same shape as ``x``.
  7081. See Also
  7082. --------
  7083. expit
  7084. Notes
  7085. -----
  7086. As a ufunc, ``log_expit`` takes a number of optional keyword arguments.
  7087. For more information see
  7088. `ufuncs <https://docs.scipy.org/doc/numpy/reference/ufuncs.html>`_
  7089. .. versionadded:: 1.8.0
  7090. Examples
  7091. --------
  7092. >>> import numpy as np
  7093. >>> from scipy.special import log_expit, expit
  7094. >>> log_expit([-3.0, 0.25, 2.5, 5.0])
  7095. array([-3.04858735, -0.57593942, -0.07888973, -0.00671535])
  7096. Large negative values:
  7097. >>> log_expit([-100, -500, -1000])
  7098. array([ -100., -500., -1000.])
  7099. Note that ``expit(-1000)`` returns 0, so the naive implementation
  7100. ``log(expit(-1000))`` return ``-inf``.
  7101. Large positive values:
  7102. >>> log_expit([29, 120, 400])
  7103. array([-2.54366565e-013, -7.66764807e-053, -1.91516960e-174])
  7104. Compare that to the naive implementation:
  7105. >>> np.log(expit([29, 120, 400]))
  7106. array([-2.54463117e-13, 0.00000000e+00, 0.00000000e+00])
  7107. The first value is accurate to only 3 digits, and the larger inputs
  7108. lose all precision and return 0.
  7109. """)
  7110. add_newdoc('logit',
  7111. """
  7112. logit(x, out=None)
  7113. Logit ufunc for ndarrays.
  7114. The logit function is defined as logit(p) = log(p/(1-p)).
  7115. Note that logit(0) = -inf, logit(1) = inf, and logit(p)
  7116. for p<0 or p>1 yields nan.
  7117. Parameters
  7118. ----------
  7119. x : ndarray
  7120. The ndarray to apply logit to element-wise.
  7121. out : ndarray, optional
  7122. Optional output array for the function results
  7123. Returns
  7124. -------
  7125. scalar or ndarray
  7126. An ndarray of the same shape as x. Its entries
  7127. are logit of the corresponding entry of x.
  7128. See Also
  7129. --------
  7130. expit
  7131. Notes
  7132. -----
  7133. As a ufunc logit takes a number of optional
  7134. keyword arguments. For more information
  7135. see `ufuncs <https://docs.scipy.org/doc/numpy/reference/ufuncs.html>`_
  7136. .. versionadded:: 0.10.0
  7137. Examples
  7138. --------
  7139. >>> import numpy as np
  7140. >>> from scipy.special import logit, expit
  7141. >>> logit([0, 0.25, 0.5, 0.75, 1])
  7142. array([ -inf, -1.09861229, 0. , 1.09861229, inf])
  7143. `expit` is the inverse of `logit`:
  7144. >>> expit(logit([0.1, 0.75, 0.999]))
  7145. array([ 0.1 , 0.75 , 0.999])
  7146. Plot logit(x) for x in [0, 1]:
  7147. >>> import matplotlib.pyplot as plt
  7148. >>> x = np.linspace(0, 1, 501)
  7149. >>> y = logit(x)
  7150. >>> plt.plot(x, y)
  7151. >>> plt.grid()
  7152. >>> plt.ylim(-6, 6)
  7153. >>> plt.xlabel('x')
  7154. >>> plt.title('logit(x)')
  7155. >>> plt.show()
  7156. """)
  7157. add_newdoc("lpmv",
  7158. r"""
  7159. lpmv(m, v, x, out=None)
  7160. Associated Legendre function of integer order and real degree.
  7161. Defined as
  7162. .. math::
  7163. P_v^m = (-1)^m (1 - x^2)^{m/2} \frac{d^m}{dx^m} P_v(x)
  7164. where
  7165. .. math::
  7166. P_v = \sum_{k = 0}^\infty \frac{(-v)_k (v + 1)_k}{(k!)^2}
  7167. \left(\frac{1 - x}{2}\right)^k
  7168. is the Legendre function of the first kind. Here :math:`(\cdot)_k`
  7169. is the Pochhammer symbol; see `poch`.
  7170. Parameters
  7171. ----------
  7172. m : array_like
  7173. Order (int or float). If passed a float not equal to an
  7174. integer the function returns NaN.
  7175. v : array_like
  7176. Degree (float).
  7177. x : array_like
  7178. Argument (float). Must have ``|x| <= 1``.
  7179. out : ndarray, optional
  7180. Optional output array for the function results
  7181. Returns
  7182. -------
  7183. pmv : scalar or ndarray
  7184. Value of the associated Legendre function.
  7185. See Also
  7186. --------
  7187. lpmn : Compute the associated Legendre function for all orders
  7188. ``0, ..., m`` and degrees ``0, ..., n``.
  7189. clpmn : Compute the associated Legendre function at complex
  7190. arguments.
  7191. Notes
  7192. -----
  7193. Note that this implementation includes the Condon-Shortley phase.
  7194. References
  7195. ----------
  7196. .. [1] Zhang, Jin, "Computation of Special Functions", John Wiley
  7197. and Sons, Inc, 1996.
  7198. """)
  7199. add_newdoc("mathieu_a",
  7200. """
  7201. mathieu_a(m, q, out=None)
  7202. Characteristic value of even Mathieu functions
  7203. Parameters
  7204. ----------
  7205. m : array_like
  7206. Order of the function
  7207. q : array_like
  7208. Parameter of the function
  7209. out : ndarray, optional
  7210. Optional output array for the function results
  7211. Returns
  7212. -------
  7213. scalar or ndarray
  7214. Characteristic value for the even solution, ``ce_m(z, q)``, of
  7215. Mathieu's equation.
  7216. See Also
  7217. --------
  7218. mathieu_b, mathieu_cem, mathieu_sem
  7219. """)
  7220. add_newdoc("mathieu_b",
  7221. """
  7222. mathieu_b(m, q, out=None)
  7223. Characteristic value of odd Mathieu functions
  7224. Parameters
  7225. ----------
  7226. m : array_like
  7227. Order of the function
  7228. q : array_like
  7229. Parameter of the function
  7230. out : ndarray, optional
  7231. Optional output array for the function results
  7232. Returns
  7233. -------
  7234. scalar or ndarray
  7235. Characteristic value for the odd solution, ``se_m(z, q)``, of Mathieu's
  7236. equation.
  7237. See Also
  7238. --------
  7239. mathieu_a, mathieu_cem, mathieu_sem
  7240. """)
  7241. add_newdoc("mathieu_cem",
  7242. """
  7243. mathieu_cem(m, q, x, out=None)
  7244. Even Mathieu function and its derivative
  7245. Returns the even Mathieu function, ``ce_m(x, q)``, of order `m` and
  7246. parameter `q` evaluated at `x` (given in degrees). Also returns the
  7247. derivative with respect to `x` of ce_m(x, q)
  7248. Parameters
  7249. ----------
  7250. m : array_like
  7251. Order of the function
  7252. q : array_like
  7253. Parameter of the function
  7254. x : array_like
  7255. Argument of the function, *given in degrees, not radians*
  7256. out : tuple of ndarray, optional
  7257. Optional output arrays for the function results
  7258. Returns
  7259. -------
  7260. y : scalar or ndarray
  7261. Value of the function
  7262. yp : scalar or ndarray
  7263. Value of the derivative vs x
  7264. See Also
  7265. --------
  7266. mathieu_a, mathieu_b, mathieu_sem
  7267. """)
  7268. add_newdoc("mathieu_modcem1",
  7269. """
  7270. mathieu_modcem1(m, q, x, out=None)
  7271. Even modified Mathieu function of the first kind and its derivative
  7272. Evaluates the even modified Mathieu function of the first kind,
  7273. ``Mc1m(x, q)``, and its derivative at `x` for order `m` and parameter
  7274. `q`.
  7275. Parameters
  7276. ----------
  7277. m : array_like
  7278. Order of the function
  7279. q : array_like
  7280. Parameter of the function
  7281. x : array_like
  7282. Argument of the function, *given in degrees, not radians*
  7283. out : tuple of ndarray, optional
  7284. Optional output arrays for the function results
  7285. Returns
  7286. -------
  7287. y : scalar or ndarray
  7288. Value of the function
  7289. yp : scalar or ndarray
  7290. Value of the derivative vs x
  7291. See Also
  7292. --------
  7293. mathieu_modsem1
  7294. """)
  7295. add_newdoc("mathieu_modcem2",
  7296. """
  7297. mathieu_modcem2(m, q, x, out=None)
  7298. Even modified Mathieu function of the second kind and its derivative
  7299. Evaluates the even modified Mathieu function of the second kind,
  7300. Mc2m(x, q), and its derivative at `x` (given in degrees) for order `m`
  7301. and parameter `q`.
  7302. Parameters
  7303. ----------
  7304. m : array_like
  7305. Order of the function
  7306. q : array_like
  7307. Parameter of the function
  7308. x : array_like
  7309. Argument of the function, *given in degrees, not radians*
  7310. out : tuple of ndarray, optional
  7311. Optional output arrays for the function results
  7312. Returns
  7313. -------
  7314. y : scalar or ndarray
  7315. Value of the function
  7316. yp : scalar or ndarray
  7317. Value of the derivative vs x
  7318. See Also
  7319. --------
  7320. mathieu_modsem2
  7321. """)
  7322. add_newdoc("mathieu_modsem1",
  7323. """
  7324. mathieu_modsem1(m, q, x, out=None)
  7325. Odd modified Mathieu function of the first kind and its derivative
  7326. Evaluates the odd modified Mathieu function of the first kind,
  7327. Ms1m(x, q), and its derivative at `x` (given in degrees) for order `m`
  7328. and parameter `q`.
  7329. Parameters
  7330. ----------
  7331. m : array_like
  7332. Order of the function
  7333. q : array_like
  7334. Parameter of the function
  7335. x : array_like
  7336. Argument of the function, *given in degrees, not radians*
  7337. out : tuple of ndarray, optional
  7338. Optional output arrays for the function results
  7339. Returns
  7340. -------
  7341. y : scalar or ndarray
  7342. Value of the function
  7343. yp : scalar or ndarray
  7344. Value of the derivative vs x
  7345. See Also
  7346. --------
  7347. mathieu_modcem1
  7348. """)
  7349. add_newdoc("mathieu_modsem2",
  7350. """
  7351. mathieu_modsem2(m, q, x, out=None)
  7352. Odd modified Mathieu function of the second kind and its derivative
  7353. Evaluates the odd modified Mathieu function of the second kind,
  7354. Ms2m(x, q), and its derivative at `x` (given in degrees) for order `m`
  7355. and parameter q.
  7356. Parameters
  7357. ----------
  7358. m : array_like
  7359. Order of the function
  7360. q : array_like
  7361. Parameter of the function
  7362. x : array_like
  7363. Argument of the function, *given in degrees, not radians*
  7364. out : tuple of ndarray, optional
  7365. Optional output arrays for the function results
  7366. Returns
  7367. -------
  7368. y : scalar or ndarray
  7369. Value of the function
  7370. yp : scalar or ndarray
  7371. Value of the derivative vs x
  7372. See Also
  7373. --------
  7374. mathieu_modcem2
  7375. """)
  7376. add_newdoc(
  7377. "mathieu_sem",
  7378. """
  7379. mathieu_sem(m, q, x, out=None)
  7380. Odd Mathieu function and its derivative
  7381. Returns the odd Mathieu function, se_m(x, q), of order `m` and
  7382. parameter `q` evaluated at `x` (given in degrees). Also returns the
  7383. derivative with respect to `x` of se_m(x, q).
  7384. Parameters
  7385. ----------
  7386. m : array_like
  7387. Order of the function
  7388. q : array_like
  7389. Parameter of the function
  7390. x : array_like
  7391. Argument of the function, *given in degrees, not radians*.
  7392. out : tuple of ndarray, optional
  7393. Optional output arrays for the function results
  7394. Returns
  7395. -------
  7396. y : scalar or ndarray
  7397. Value of the function
  7398. yp : scalar or ndarray
  7399. Value of the derivative vs x
  7400. See Also
  7401. --------
  7402. mathieu_a, mathieu_b, mathieu_cem
  7403. """)
  7404. add_newdoc("modfresnelm",
  7405. """
  7406. modfresnelm(x, out=None)
  7407. Modified Fresnel negative integrals
  7408. Parameters
  7409. ----------
  7410. x : array_like
  7411. Function argument
  7412. out : tuple of ndarray, optional
  7413. Optional output arrays for the function results
  7414. Returns
  7415. -------
  7416. fm : scalar or ndarray
  7417. Integral ``F_-(x)``: ``integral(exp(-1j*t*t), t=x..inf)``
  7418. km : scalar or ndarray
  7419. Integral ``K_-(x)``: ``1/sqrt(pi)*exp(1j*(x*x+pi/4))*fp``
  7420. See Also
  7421. --------
  7422. modfresnelp
  7423. """)
  7424. add_newdoc("modfresnelp",
  7425. """
  7426. modfresnelp(x, out=None)
  7427. Modified Fresnel positive integrals
  7428. Parameters
  7429. ----------
  7430. x : array_like
  7431. Function argument
  7432. out : tuple of ndarray, optional
  7433. Optional output arrays for the function results
  7434. Returns
  7435. -------
  7436. fp : scalar or ndarray
  7437. Integral ``F_+(x)``: ``integral(exp(1j*t*t), t=x..inf)``
  7438. kp : scalar or ndarray
  7439. Integral ``K_+(x)``: ``1/sqrt(pi)*exp(-1j*(x*x+pi/4))*fp``
  7440. See Also
  7441. --------
  7442. modfresnelm
  7443. """)
  7444. add_newdoc("modstruve",
  7445. r"""
  7446. modstruve(v, x, out=None)
  7447. Modified Struve function.
  7448. Return the value of the modified Struve function of order `v` at `x`. The
  7449. modified Struve function is defined as,
  7450. .. math::
  7451. L_v(x) = -\imath \exp(-\pi\imath v/2) H_v(\imath x),
  7452. where :math:`H_v` is the Struve function.
  7453. Parameters
  7454. ----------
  7455. v : array_like
  7456. Order of the modified Struve function (float).
  7457. x : array_like
  7458. Argument of the Struve function (float; must be positive unless `v` is
  7459. an integer).
  7460. out : ndarray, optional
  7461. Optional output array for the function results
  7462. Returns
  7463. -------
  7464. L : scalar or ndarray
  7465. Value of the modified Struve function of order `v` at `x`.
  7466. Notes
  7467. -----
  7468. Three methods discussed in [1]_ are used to evaluate the function:
  7469. - power series
  7470. - expansion in Bessel functions (if :math:`|x| < |v| + 20`)
  7471. - asymptotic large-x expansion (if :math:`x \geq 0.7v + 12`)
  7472. Rounding errors are estimated based on the largest terms in the sums, and
  7473. the result associated with the smallest error is returned.
  7474. See also
  7475. --------
  7476. struve
  7477. References
  7478. ----------
  7479. .. [1] NIST Digital Library of Mathematical Functions
  7480. https://dlmf.nist.gov/11
  7481. Examples
  7482. --------
  7483. Calculate the modified Struve function of order 1 at 2.
  7484. >>> import numpy as np
  7485. >>> from scipy.special import modstruve
  7486. >>> import matplotlib.pyplot as plt
  7487. >>> modstruve(1, 2.)
  7488. 1.102759787367716
  7489. Calculate the modified Struve function at 2 for orders 1, 2 and 3 by
  7490. providing a list for the order parameter `v`.
  7491. >>> modstruve([1, 2, 3], 2.)
  7492. array([1.10275979, 0.41026079, 0.11247294])
  7493. Calculate the modified Struve function of order 1 for several points
  7494. by providing an array for `x`.
  7495. >>> points = np.array([2., 5., 8.])
  7496. >>> modstruve(1, points)
  7497. array([ 1.10275979, 23.72821578, 399.24709139])
  7498. Compute the modified Struve function for several orders at several
  7499. points by providing arrays for `v` and `z`. The arrays have to be
  7500. broadcastable to the correct shapes.
  7501. >>> orders = np.array([[1], [2], [3]])
  7502. >>> points.shape, orders.shape
  7503. ((3,), (3, 1))
  7504. >>> modstruve(orders, points)
  7505. array([[1.10275979e+00, 2.37282158e+01, 3.99247091e+02],
  7506. [4.10260789e-01, 1.65535979e+01, 3.25973609e+02],
  7507. [1.12472937e-01, 9.42430454e+00, 2.33544042e+02]])
  7508. Plot the modified Struve functions of order 0 to 3 from -5 to 5.
  7509. >>> fig, ax = plt.subplots()
  7510. >>> x = np.linspace(-5., 5., 1000)
  7511. >>> for i in range(4):
  7512. ... ax.plot(x, modstruve(i, x), label=f'$L_{i!r}$')
  7513. >>> ax.legend(ncol=2)
  7514. >>> ax.set_xlim(-5, 5)
  7515. >>> ax.set_title(r"Modified Struve functions $L_{\nu}$")
  7516. >>> plt.show()
  7517. """)
  7518. add_newdoc("nbdtr",
  7519. r"""
  7520. nbdtr(k, n, p, out=None)
  7521. Negative binomial cumulative distribution function.
  7522. Returns the sum of the terms 0 through `k` of the negative binomial
  7523. distribution probability mass function,
  7524. .. math::
  7525. F = \sum_{j=0}^k {{n + j - 1}\choose{j}} p^n (1 - p)^j.
  7526. In a sequence of Bernoulli trials with individual success probabilities
  7527. `p`, this is the probability that `k` or fewer failures precede the nth
  7528. success.
  7529. Parameters
  7530. ----------
  7531. k : array_like
  7532. The maximum number of allowed failures (nonnegative int).
  7533. n : array_like
  7534. The target number of successes (positive int).
  7535. p : array_like
  7536. Probability of success in a single event (float).
  7537. out : ndarray, optional
  7538. Optional output array for the function results
  7539. Returns
  7540. -------
  7541. F : scalar or ndarray
  7542. The probability of `k` or fewer failures before `n` successes in a
  7543. sequence of events with individual success probability `p`.
  7544. See also
  7545. --------
  7546. nbdtrc
  7547. Notes
  7548. -----
  7549. If floating point values are passed for `k` or `n`, they will be truncated
  7550. to integers.
  7551. The terms are not summed directly; instead the regularized incomplete beta
  7552. function is employed, according to the formula,
  7553. .. math::
  7554. \mathrm{nbdtr}(k, n, p) = I_{p}(n, k + 1).
  7555. Wrapper for the Cephes [1]_ routine `nbdtr`.
  7556. References
  7557. ----------
  7558. .. [1] Cephes Mathematical Functions Library,
  7559. http://www.netlib.org/cephes/
  7560. """)
  7561. add_newdoc("nbdtrc",
  7562. r"""
  7563. nbdtrc(k, n, p, out=None)
  7564. Negative binomial survival function.
  7565. Returns the sum of the terms `k + 1` to infinity of the negative binomial
  7566. distribution probability mass function,
  7567. .. math::
  7568. F = \sum_{j=k + 1}^\infty {{n + j - 1}\choose{j}} p^n (1 - p)^j.
  7569. In a sequence of Bernoulli trials with individual success probabilities
  7570. `p`, this is the probability that more than `k` failures precede the nth
  7571. success.
  7572. Parameters
  7573. ----------
  7574. k : array_like
  7575. The maximum number of allowed failures (nonnegative int).
  7576. n : array_like
  7577. The target number of successes (positive int).
  7578. p : array_like
  7579. Probability of success in a single event (float).
  7580. out : ndarray, optional
  7581. Optional output array for the function results
  7582. Returns
  7583. -------
  7584. F : scalar or ndarray
  7585. The probability of `k + 1` or more failures before `n` successes in a
  7586. sequence of events with individual success probability `p`.
  7587. Notes
  7588. -----
  7589. If floating point values are passed for `k` or `n`, they will be truncated
  7590. to integers.
  7591. The terms are not summed directly; instead the regularized incomplete beta
  7592. function is employed, according to the formula,
  7593. .. math::
  7594. \mathrm{nbdtrc}(k, n, p) = I_{1 - p}(k + 1, n).
  7595. Wrapper for the Cephes [1]_ routine `nbdtrc`.
  7596. References
  7597. ----------
  7598. .. [1] Cephes Mathematical Functions Library,
  7599. http://www.netlib.org/cephes/
  7600. """)
  7601. add_newdoc("nbdtri",
  7602. """
  7603. nbdtri(k, n, y, out=None)
  7604. Inverse of `nbdtr` vs `p`.
  7605. Returns the inverse with respect to the parameter `p` of
  7606. `y = nbdtr(k, n, p)`, the negative binomial cumulative distribution
  7607. function.
  7608. Parameters
  7609. ----------
  7610. k : array_like
  7611. The maximum number of allowed failures (nonnegative int).
  7612. n : array_like
  7613. The target number of successes (positive int).
  7614. y : array_like
  7615. The probability of `k` or fewer failures before `n` successes (float).
  7616. out : ndarray, optional
  7617. Optional output array for the function results
  7618. Returns
  7619. -------
  7620. p : scalar or ndarray
  7621. Probability of success in a single event (float) such that
  7622. `nbdtr(k, n, p) = y`.
  7623. See also
  7624. --------
  7625. nbdtr : Cumulative distribution function of the negative binomial.
  7626. nbdtrik : Inverse with respect to `k` of `nbdtr(k, n, p)`.
  7627. nbdtrin : Inverse with respect to `n` of `nbdtr(k, n, p)`.
  7628. Notes
  7629. -----
  7630. Wrapper for the Cephes [1]_ routine `nbdtri`.
  7631. References
  7632. ----------
  7633. .. [1] Cephes Mathematical Functions Library,
  7634. http://www.netlib.org/cephes/
  7635. """)
  7636. add_newdoc("nbdtrik",
  7637. r"""
  7638. nbdtrik(y, n, p, out=None)
  7639. Inverse of `nbdtr` vs `k`.
  7640. Returns the inverse with respect to the parameter `k` of
  7641. `y = nbdtr(k, n, p)`, the negative binomial cumulative distribution
  7642. function.
  7643. Parameters
  7644. ----------
  7645. y : array_like
  7646. The probability of `k` or fewer failures before `n` successes (float).
  7647. n : array_like
  7648. The target number of successes (positive int).
  7649. p : array_like
  7650. Probability of success in a single event (float).
  7651. out : ndarray, optional
  7652. Optional output array for the function results
  7653. Returns
  7654. -------
  7655. k : scalar or ndarray
  7656. The maximum number of allowed failures such that `nbdtr(k, n, p) = y`.
  7657. See also
  7658. --------
  7659. nbdtr : Cumulative distribution function of the negative binomial.
  7660. nbdtri : Inverse with respect to `p` of `nbdtr(k, n, p)`.
  7661. nbdtrin : Inverse with respect to `n` of `nbdtr(k, n, p)`.
  7662. Notes
  7663. -----
  7664. Wrapper for the CDFLIB [1]_ Fortran routine `cdfnbn`.
  7665. Formula 26.5.26 of [2]_,
  7666. .. math::
  7667. \sum_{j=k + 1}^\infty {{n + j - 1}\choose{j}} p^n (1 - p)^j = I_{1 - p}(k + 1, n),
  7668. is used to reduce calculation of the cumulative distribution function to
  7669. that of a regularized incomplete beta :math:`I`.
  7670. Computation of `k` involves a search for a value that produces the desired
  7671. value of `y`. The search relies on the monotonicity of `y` with `k`.
  7672. References
  7673. ----------
  7674. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  7675. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  7676. Functions, Inverses, and Other Parameters.
  7677. .. [2] Milton Abramowitz and Irene A. Stegun, eds.
  7678. Handbook of Mathematical Functions with Formulas,
  7679. Graphs, and Mathematical Tables. New York: Dover, 1972.
  7680. """)
  7681. add_newdoc("nbdtrin",
  7682. r"""
  7683. nbdtrin(k, y, p, out=None)
  7684. Inverse of `nbdtr` vs `n`.
  7685. Returns the inverse with respect to the parameter `n` of
  7686. `y = nbdtr(k, n, p)`, the negative binomial cumulative distribution
  7687. function.
  7688. Parameters
  7689. ----------
  7690. k : array_like
  7691. The maximum number of allowed failures (nonnegative int).
  7692. y : array_like
  7693. The probability of `k` or fewer failures before `n` successes (float).
  7694. p : array_like
  7695. Probability of success in a single event (float).
  7696. out : ndarray, optional
  7697. Optional output array for the function results
  7698. Returns
  7699. -------
  7700. n : scalar or ndarray
  7701. The number of successes `n` such that `nbdtr(k, n, p) = y`.
  7702. See also
  7703. --------
  7704. nbdtr : Cumulative distribution function of the negative binomial.
  7705. nbdtri : Inverse with respect to `p` of `nbdtr(k, n, p)`.
  7706. nbdtrik : Inverse with respect to `k` of `nbdtr(k, n, p)`.
  7707. Notes
  7708. -----
  7709. Wrapper for the CDFLIB [1]_ Fortran routine `cdfnbn`.
  7710. Formula 26.5.26 of [2]_,
  7711. .. math::
  7712. \sum_{j=k + 1}^\infty {{n + j - 1}\choose{j}} p^n (1 - p)^j = I_{1 - p}(k + 1, n),
  7713. is used to reduce calculation of the cumulative distribution function to
  7714. that of a regularized incomplete beta :math:`I`.
  7715. Computation of `n` involves a search for a value that produces the desired
  7716. value of `y`. The search relies on the monotonicity of `y` with `n`.
  7717. References
  7718. ----------
  7719. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  7720. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  7721. Functions, Inverses, and Other Parameters.
  7722. .. [2] Milton Abramowitz and Irene A. Stegun, eds.
  7723. Handbook of Mathematical Functions with Formulas,
  7724. Graphs, and Mathematical Tables. New York: Dover, 1972.
  7725. """)
  7726. add_newdoc("ncfdtr",
  7727. r"""
  7728. ncfdtr(dfn, dfd, nc, f, out=None)
  7729. Cumulative distribution function of the non-central F distribution.
  7730. The non-central F describes the distribution of,
  7731. .. math::
  7732. Z = \frac{X/d_n}{Y/d_d}
  7733. where :math:`X` and :math:`Y` are independently distributed, with
  7734. :math:`X` distributed non-central :math:`\chi^2` with noncentrality
  7735. parameter `nc` and :math:`d_n` degrees of freedom, and :math:`Y`
  7736. distributed :math:`\chi^2` with :math:`d_d` degrees of freedom.
  7737. Parameters
  7738. ----------
  7739. dfn : array_like
  7740. Degrees of freedom of the numerator sum of squares. Range (0, inf).
  7741. dfd : array_like
  7742. Degrees of freedom of the denominator sum of squares. Range (0, inf).
  7743. nc : array_like
  7744. Noncentrality parameter. Should be in range (0, 1e4).
  7745. f : array_like
  7746. Quantiles, i.e. the upper limit of integration.
  7747. out : ndarray, optional
  7748. Optional output array for the function results
  7749. Returns
  7750. -------
  7751. cdf : scalar or ndarray
  7752. The calculated CDF. If all inputs are scalar, the return will be a
  7753. float. Otherwise it will be an array.
  7754. See Also
  7755. --------
  7756. ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
  7757. ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
  7758. ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
  7759. ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
  7760. Notes
  7761. -----
  7762. Wrapper for the CDFLIB [1]_ Fortran routine `cdffnc`.
  7763. The cumulative distribution function is computed using Formula 26.6.20 of
  7764. [2]_:
  7765. .. math::
  7766. F(d_n, d_d, n_c, f) = \sum_{j=0}^\infty e^{-n_c/2} \frac{(n_c/2)^j}{j!} I_{x}(\frac{d_n}{2} + j, \frac{d_d}{2}),
  7767. where :math:`I` is the regularized incomplete beta function, and
  7768. :math:`x = f d_n/(f d_n + d_d)`.
  7769. The computation time required for this routine is proportional to the
  7770. noncentrality parameter `nc`. Very large values of this parameter can
  7771. consume immense computer resources. This is why the search range is
  7772. bounded by 10,000.
  7773. References
  7774. ----------
  7775. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  7776. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  7777. Functions, Inverses, and Other Parameters.
  7778. .. [2] Milton Abramowitz and Irene A. Stegun, eds.
  7779. Handbook of Mathematical Functions with Formulas,
  7780. Graphs, and Mathematical Tables. New York: Dover, 1972.
  7781. Examples
  7782. --------
  7783. >>> import numpy as np
  7784. >>> from scipy import special
  7785. >>> from scipy import stats
  7786. >>> import matplotlib.pyplot as plt
  7787. Plot the CDF of the non-central F distribution, for nc=0. Compare with the
  7788. F-distribution from scipy.stats:
  7789. >>> x = np.linspace(-1, 8, num=500)
  7790. >>> dfn = 3
  7791. >>> dfd = 2
  7792. >>> ncf_stats = stats.f.cdf(x, dfn, dfd)
  7793. >>> ncf_special = special.ncfdtr(dfn, dfd, 0, x)
  7794. >>> fig = plt.figure()
  7795. >>> ax = fig.add_subplot(111)
  7796. >>> ax.plot(x, ncf_stats, 'b-', lw=3)
  7797. >>> ax.plot(x, ncf_special, 'r-')
  7798. >>> plt.show()
  7799. """)
  7800. add_newdoc("ncfdtri",
  7801. """
  7802. ncfdtri(dfn, dfd, nc, p, out=None)
  7803. Inverse with respect to `f` of the CDF of the non-central F distribution.
  7804. See `ncfdtr` for more details.
  7805. Parameters
  7806. ----------
  7807. dfn : array_like
  7808. Degrees of freedom of the numerator sum of squares. Range (0, inf).
  7809. dfd : array_like
  7810. Degrees of freedom of the denominator sum of squares. Range (0, inf).
  7811. nc : array_like
  7812. Noncentrality parameter. Should be in range (0, 1e4).
  7813. p : array_like
  7814. Value of the cumulative distribution function. Must be in the
  7815. range [0, 1].
  7816. out : ndarray, optional
  7817. Optional output array for the function results
  7818. Returns
  7819. -------
  7820. f : scalar or ndarray
  7821. Quantiles, i.e., the upper limit of integration.
  7822. See Also
  7823. --------
  7824. ncfdtr : CDF of the non-central F distribution.
  7825. ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
  7826. ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
  7827. ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
  7828. Examples
  7829. --------
  7830. >>> from scipy.special import ncfdtr, ncfdtri
  7831. Compute the CDF for several values of `f`:
  7832. >>> f = [0.5, 1, 1.5]
  7833. >>> p = ncfdtr(2, 3, 1.5, f)
  7834. >>> p
  7835. array([ 0.20782291, 0.36107392, 0.47345752])
  7836. Compute the inverse. We recover the values of `f`, as expected:
  7837. >>> ncfdtri(2, 3, 1.5, p)
  7838. array([ 0.5, 1. , 1.5])
  7839. """)
  7840. add_newdoc("ncfdtridfd",
  7841. """
  7842. ncfdtridfd(dfn, p, nc, f, out=None)
  7843. Calculate degrees of freedom (denominator) for the noncentral F-distribution.
  7844. This is the inverse with respect to `dfd` of `ncfdtr`.
  7845. See `ncfdtr` for more details.
  7846. Parameters
  7847. ----------
  7848. dfn : array_like
  7849. Degrees of freedom of the numerator sum of squares. Range (0, inf).
  7850. p : array_like
  7851. Value of the cumulative distribution function. Must be in the
  7852. range [0, 1].
  7853. nc : array_like
  7854. Noncentrality parameter. Should be in range (0, 1e4).
  7855. f : array_like
  7856. Quantiles, i.e., the upper limit of integration.
  7857. out : ndarray, optional
  7858. Optional output array for the function results
  7859. Returns
  7860. -------
  7861. dfd : scalar or ndarray
  7862. Degrees of freedom of the denominator sum of squares.
  7863. See Also
  7864. --------
  7865. ncfdtr : CDF of the non-central F distribution.
  7866. ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
  7867. ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
  7868. ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
  7869. Notes
  7870. -----
  7871. The value of the cumulative noncentral F distribution is not necessarily
  7872. monotone in either degrees of freedom. There thus may be two values that
  7873. provide a given CDF value. This routine assumes monotonicity and will
  7874. find an arbitrary one of the two values.
  7875. Examples
  7876. --------
  7877. >>> from scipy.special import ncfdtr, ncfdtridfd
  7878. Compute the CDF for several values of `dfd`:
  7879. >>> dfd = [1, 2, 3]
  7880. >>> p = ncfdtr(2, dfd, 0.25, 15)
  7881. >>> p
  7882. array([ 0.8097138 , 0.93020416, 0.96787852])
  7883. Compute the inverse. We recover the values of `dfd`, as expected:
  7884. >>> ncfdtridfd(2, p, 0.25, 15)
  7885. array([ 1., 2., 3.])
  7886. """)
  7887. add_newdoc("ncfdtridfn",
  7888. """
  7889. ncfdtridfn(p, dfd, nc, f, out=None)
  7890. Calculate degrees of freedom (numerator) for the noncentral F-distribution.
  7891. This is the inverse with respect to `dfn` of `ncfdtr`.
  7892. See `ncfdtr` for more details.
  7893. Parameters
  7894. ----------
  7895. p : array_like
  7896. Value of the cumulative distribution function. Must be in the
  7897. range [0, 1].
  7898. dfd : array_like
  7899. Degrees of freedom of the denominator sum of squares. Range (0, inf).
  7900. nc : array_like
  7901. Noncentrality parameter. Should be in range (0, 1e4).
  7902. f : float
  7903. Quantiles, i.e., the upper limit of integration.
  7904. out : ndarray, optional
  7905. Optional output array for the function results
  7906. Returns
  7907. -------
  7908. dfn : scalar or ndarray
  7909. Degrees of freedom of the numerator sum of squares.
  7910. See Also
  7911. --------
  7912. ncfdtr : CDF of the non-central F distribution.
  7913. ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
  7914. ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
  7915. ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
  7916. Notes
  7917. -----
  7918. The value of the cumulative noncentral F distribution is not necessarily
  7919. monotone in either degrees of freedom. There thus may be two values that
  7920. provide a given CDF value. This routine assumes monotonicity and will
  7921. find an arbitrary one of the two values.
  7922. Examples
  7923. --------
  7924. >>> from scipy.special import ncfdtr, ncfdtridfn
  7925. Compute the CDF for several values of `dfn`:
  7926. >>> dfn = [1, 2, 3]
  7927. >>> p = ncfdtr(dfn, 2, 0.25, 15)
  7928. >>> p
  7929. array([ 0.92562363, 0.93020416, 0.93188394])
  7930. Compute the inverse. We recover the values of `dfn`, as expected:
  7931. >>> ncfdtridfn(p, 2, 0.25, 15)
  7932. array([ 1., 2., 3.])
  7933. """)
  7934. add_newdoc("ncfdtrinc",
  7935. """
  7936. ncfdtrinc(dfn, dfd, p, f, out=None)
  7937. Calculate non-centrality parameter for non-central F distribution.
  7938. This is the inverse with respect to `nc` of `ncfdtr`.
  7939. See `ncfdtr` for more details.
  7940. Parameters
  7941. ----------
  7942. dfn : array_like
  7943. Degrees of freedom of the numerator sum of squares. Range (0, inf).
  7944. dfd : array_like
  7945. Degrees of freedom of the denominator sum of squares. Range (0, inf).
  7946. p : array_like
  7947. Value of the cumulative distribution function. Must be in the
  7948. range [0, 1].
  7949. f : array_like
  7950. Quantiles, i.e., the upper limit of integration.
  7951. out : ndarray, optional
  7952. Optional output array for the function results
  7953. Returns
  7954. -------
  7955. nc : scalar or ndarray
  7956. Noncentrality parameter.
  7957. See Also
  7958. --------
  7959. ncfdtr : CDF of the non-central F distribution.
  7960. ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
  7961. ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
  7962. ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
  7963. Examples
  7964. --------
  7965. >>> from scipy.special import ncfdtr, ncfdtrinc
  7966. Compute the CDF for several values of `nc`:
  7967. >>> nc = [0.5, 1.5, 2.0]
  7968. >>> p = ncfdtr(2, 3, nc, 15)
  7969. >>> p
  7970. array([ 0.96309246, 0.94327955, 0.93304098])
  7971. Compute the inverse. We recover the values of `nc`, as expected:
  7972. >>> ncfdtrinc(2, 3, p, 15)
  7973. array([ 0.5, 1.5, 2. ])
  7974. """)
  7975. add_newdoc("nctdtr",
  7976. """
  7977. nctdtr(df, nc, t, out=None)
  7978. Cumulative distribution function of the non-central `t` distribution.
  7979. Parameters
  7980. ----------
  7981. df : array_like
  7982. Degrees of freedom of the distribution. Should be in range (0, inf).
  7983. nc : array_like
  7984. Noncentrality parameter. Should be in range (-1e6, 1e6).
  7985. t : array_like
  7986. Quantiles, i.e., the upper limit of integration.
  7987. out : ndarray, optional
  7988. Optional output array for the function results
  7989. Returns
  7990. -------
  7991. cdf : scalar or ndarray
  7992. The calculated CDF. If all inputs are scalar, the return will be a
  7993. float. Otherwise, it will be an array.
  7994. See Also
  7995. --------
  7996. nctdtrit : Inverse CDF (iCDF) of the non-central t distribution.
  7997. nctdtridf : Calculate degrees of freedom, given CDF and iCDF values.
  7998. nctdtrinc : Calculate non-centrality parameter, given CDF iCDF values.
  7999. Examples
  8000. --------
  8001. >>> import numpy as np
  8002. >>> from scipy import special
  8003. >>> from scipy import stats
  8004. >>> import matplotlib.pyplot as plt
  8005. Plot the CDF of the non-central t distribution, for nc=0. Compare with the
  8006. t-distribution from scipy.stats:
  8007. >>> x = np.linspace(-5, 5, num=500)
  8008. >>> df = 3
  8009. >>> nct_stats = stats.t.cdf(x, df)
  8010. >>> nct_special = special.nctdtr(df, 0, x)
  8011. >>> fig = plt.figure()
  8012. >>> ax = fig.add_subplot(111)
  8013. >>> ax.plot(x, nct_stats, 'b-', lw=3)
  8014. >>> ax.plot(x, nct_special, 'r-')
  8015. >>> plt.show()
  8016. """)
  8017. add_newdoc("nctdtridf",
  8018. """
  8019. nctdtridf(p, nc, t, out=None)
  8020. Calculate degrees of freedom for non-central t distribution.
  8021. See `nctdtr` for more details.
  8022. Parameters
  8023. ----------
  8024. p : array_like
  8025. CDF values, in range (0, 1].
  8026. nc : array_like
  8027. Noncentrality parameter. Should be in range (-1e6, 1e6).
  8028. t : array_like
  8029. Quantiles, i.e., the upper limit of integration.
  8030. out : ndarray, optional
  8031. Optional output array for the function results
  8032. Returns
  8033. -------
  8034. cdf : scalar or ndarray
  8035. The calculated CDF. If all inputs are scalar, the return will be a
  8036. float. Otherwise, it will be an array.
  8037. See Also
  8038. --------
  8039. nctdtr : CDF of the non-central `t` distribution.
  8040. nctdtrit : Inverse CDF (iCDF) of the non-central t distribution.
  8041. nctdtrinc : Calculate non-centrality parameter, given CDF iCDF values.
  8042. """)
  8043. add_newdoc("nctdtrinc",
  8044. """
  8045. nctdtrinc(df, p, t, out=None)
  8046. Calculate non-centrality parameter for non-central t distribution.
  8047. See `nctdtr` for more details.
  8048. Parameters
  8049. ----------
  8050. df : array_like
  8051. Degrees of freedom of the distribution. Should be in range (0, inf).
  8052. p : array_like
  8053. CDF values, in range (0, 1].
  8054. t : array_like
  8055. Quantiles, i.e., the upper limit of integration.
  8056. out : ndarray, optional
  8057. Optional output array for the function results
  8058. Returns
  8059. -------
  8060. nc : scalar or ndarray
  8061. Noncentrality parameter
  8062. See Also
  8063. --------
  8064. nctdtr : CDF of the non-central `t` distribution.
  8065. nctdtrit : Inverse CDF (iCDF) of the non-central t distribution.
  8066. nctdtridf : Calculate degrees of freedom, given CDF and iCDF values.
  8067. """)
  8068. add_newdoc("nctdtrit",
  8069. """
  8070. nctdtrit(df, nc, p, out=None)
  8071. Inverse cumulative distribution function of the non-central t distribution.
  8072. See `nctdtr` for more details.
  8073. Parameters
  8074. ----------
  8075. df : array_like
  8076. Degrees of freedom of the distribution. Should be in range (0, inf).
  8077. nc : array_like
  8078. Noncentrality parameter. Should be in range (-1e6, 1e6).
  8079. p : array_like
  8080. CDF values, in range (0, 1].
  8081. out : ndarray, optional
  8082. Optional output array for the function results
  8083. Returns
  8084. -------
  8085. t : scalar or ndarray
  8086. Quantiles
  8087. See Also
  8088. --------
  8089. nctdtr : CDF of the non-central `t` distribution.
  8090. nctdtridf : Calculate degrees of freedom, given CDF and iCDF values.
  8091. nctdtrinc : Calculate non-centrality parameter, given CDF iCDF values.
  8092. """)
  8093. add_newdoc("ndtr",
  8094. r"""
  8095. ndtr(x, out=None)
  8096. Gaussian cumulative distribution function.
  8097. Returns the area under the standard Gaussian probability
  8098. density function, integrated from minus infinity to `x`
  8099. .. math::
  8100. \frac{1}{\sqrt{2\pi}} \int_{-\infty}^x \exp(-t^2/2) dt
  8101. Parameters
  8102. ----------
  8103. x : array_like, real or complex
  8104. Argument
  8105. out : ndarray, optional
  8106. Optional output array for the function results
  8107. Returns
  8108. -------
  8109. scalar or ndarray
  8110. The value of the normal CDF evaluated at `x`
  8111. See Also
  8112. --------
  8113. erf, erfc, scipy.stats.norm, log_ndtr
  8114. """)
  8115. add_newdoc("nrdtrimn",
  8116. """
  8117. nrdtrimn(p, x, std, out=None)
  8118. Calculate mean of normal distribution given other params.
  8119. Parameters
  8120. ----------
  8121. p : array_like
  8122. CDF values, in range (0, 1].
  8123. x : array_like
  8124. Quantiles, i.e. the upper limit of integration.
  8125. std : array_like
  8126. Standard deviation.
  8127. out : ndarray, optional
  8128. Optional output array for the function results
  8129. Returns
  8130. -------
  8131. mn : scalar or ndarray
  8132. The mean of the normal distribution.
  8133. See Also
  8134. --------
  8135. nrdtrimn, ndtr
  8136. """)
  8137. add_newdoc("nrdtrisd",
  8138. """
  8139. nrdtrisd(p, x, mn, out=None)
  8140. Calculate standard deviation of normal distribution given other params.
  8141. Parameters
  8142. ----------
  8143. p : array_like
  8144. CDF values, in range (0, 1].
  8145. x : array_like
  8146. Quantiles, i.e. the upper limit of integration.
  8147. mn : scalar or ndarray
  8148. The mean of the normal distribution.
  8149. out : ndarray, optional
  8150. Optional output array for the function results
  8151. Returns
  8152. -------
  8153. std : scalar or ndarray
  8154. Standard deviation.
  8155. See Also
  8156. --------
  8157. ndtr
  8158. """)
  8159. add_newdoc("log_ndtr",
  8160. """
  8161. log_ndtr(x, out=None)
  8162. Logarithm of Gaussian cumulative distribution function.
  8163. Returns the log of the area under the standard Gaussian probability
  8164. density function, integrated from minus infinity to `x`::
  8165. log(1/sqrt(2*pi) * integral(exp(-t**2 / 2), t=-inf..x))
  8166. Parameters
  8167. ----------
  8168. x : array_like, real or complex
  8169. Argument
  8170. out : ndarray, optional
  8171. Optional output array for the function results
  8172. Returns
  8173. -------
  8174. scalar or ndarray
  8175. The value of the log of the normal CDF evaluated at `x`
  8176. See Also
  8177. --------
  8178. erf
  8179. erfc
  8180. scipy.stats.norm
  8181. ndtr
  8182. Examples
  8183. --------
  8184. >>> import numpy as np
  8185. >>> from scipy.special import log_ndtr, ndtr
  8186. The benefit of ``log_ndtr(x)`` over the naive implementation
  8187. ``np.log(ndtr(x))`` is most evident with moderate to large positive
  8188. values of ``x``:
  8189. >>> x = np.array([6, 7, 9, 12, 15, 25])
  8190. >>> log_ndtr(x)
  8191. array([-9.86587646e-010, -1.27981254e-012, -1.12858841e-019,
  8192. -1.77648211e-033, -3.67096620e-051, -3.05669671e-138])
  8193. The results of the naive calculation for the moderate ``x`` values
  8194. have only 5 or 6 correct significant digits. For values of ``x``
  8195. greater than approximately 8.3, the naive expression returns 0:
  8196. >>> np.log(ndtr(x))
  8197. array([-9.86587701e-10, -1.27986510e-12, 0.00000000e+00,
  8198. 0.00000000e+00, 0.00000000e+00, 0.00000000e+00])
  8199. """)
  8200. add_newdoc("ndtri",
  8201. """
  8202. ndtri(y, out=None)
  8203. Inverse of `ndtr` vs x
  8204. Returns the argument x for which the area under the Gaussian
  8205. probability density function (integrated from minus infinity to `x`)
  8206. is equal to y.
  8207. Parameters
  8208. ----------
  8209. p : array_like
  8210. Probability
  8211. out : ndarray, optional
  8212. Optional output array for the function results
  8213. Returns
  8214. -------
  8215. x : scalar or ndarray
  8216. Value of x such that ``ndtr(x) == p``.
  8217. See Also
  8218. --------
  8219. ndtr
  8220. """)
  8221. add_newdoc("obl_ang1",
  8222. """
  8223. obl_ang1(m, n, c, x, out=None)
  8224. Oblate spheroidal angular function of the first kind and its derivative
  8225. Computes the oblate spheroidal angular function of the first kind
  8226. and its derivative (with respect to `x`) for mode parameters m>=0
  8227. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``.
  8228. Parameters
  8229. ----------
  8230. m : array_like
  8231. Mode parameter m (nonnegative)
  8232. n : array_like
  8233. Mode parameter n (>= m)
  8234. c : array_like
  8235. Spheroidal parameter
  8236. x : array_like
  8237. Parameter x (``|x| < 1.0``)
  8238. out : ndarray, optional
  8239. Optional output array for the function results
  8240. Returns
  8241. -------
  8242. s : scalar or ndarray
  8243. Value of the function
  8244. sp : scalar or ndarray
  8245. Value of the derivative vs x
  8246. See Also
  8247. --------
  8248. obl_ang1_cv
  8249. """)
  8250. add_newdoc("obl_ang1_cv",
  8251. """
  8252. obl_ang1_cv(m, n, c, cv, x, out=None)
  8253. Oblate spheroidal angular function obl_ang1 for precomputed characteristic value
  8254. Computes the oblate spheroidal angular function of the first kind
  8255. and its derivative (with respect to `x`) for mode parameters m>=0
  8256. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``. Requires
  8257. pre-computed characteristic value.
  8258. Parameters
  8259. ----------
  8260. m : array_like
  8261. Mode parameter m (nonnegative)
  8262. n : array_like
  8263. Mode parameter n (>= m)
  8264. c : array_like
  8265. Spheroidal parameter
  8266. cv : array_like
  8267. Characteristic value
  8268. x : array_like
  8269. Parameter x (``|x| < 1.0``)
  8270. out : ndarray, optional
  8271. Optional output array for the function results
  8272. Returns
  8273. -------
  8274. s : scalar or ndarray
  8275. Value of the function
  8276. sp : scalar or ndarray
  8277. Value of the derivative vs x
  8278. See Also
  8279. --------
  8280. obl_ang1
  8281. """)
  8282. add_newdoc("obl_cv",
  8283. """
  8284. obl_cv(m, n, c, out=None)
  8285. Characteristic value of oblate spheroidal function
  8286. Computes the characteristic value of oblate spheroidal wave
  8287. functions of order `m`, `n` (n>=m) and spheroidal parameter `c`.
  8288. Parameters
  8289. ----------
  8290. m : array_like
  8291. Mode parameter m (nonnegative)
  8292. n : array_like
  8293. Mode parameter n (>= m)
  8294. c : array_like
  8295. Spheroidal parameter
  8296. out : ndarray, optional
  8297. Optional output array for the function results
  8298. Returns
  8299. -------
  8300. cv : scalar or ndarray
  8301. Characteristic value
  8302. """)
  8303. add_newdoc("obl_rad1",
  8304. """
  8305. obl_rad1(m, n, c, x, out=None)
  8306. Oblate spheroidal radial function of the first kind and its derivative
  8307. Computes the oblate spheroidal radial function of the first kind
  8308. and its derivative (with respect to `x`) for mode parameters m>=0
  8309. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``.
  8310. Parameters
  8311. ----------
  8312. m : array_like
  8313. Mode parameter m (nonnegative)
  8314. n : array_like
  8315. Mode parameter n (>= m)
  8316. c : array_like
  8317. Spheroidal parameter
  8318. x : array_like
  8319. Parameter x (``|x| < 1.0``)
  8320. out : ndarray, optional
  8321. Optional output array for the function results
  8322. Returns
  8323. -------
  8324. s : scalar or ndarray
  8325. Value of the function
  8326. sp : scalar or ndarray
  8327. Value of the derivative vs x
  8328. See Also
  8329. --------
  8330. obl_rad1_cv
  8331. """)
  8332. add_newdoc("obl_rad1_cv",
  8333. """
  8334. obl_rad1_cv(m, n, c, cv, x, out=None)
  8335. Oblate spheroidal radial function obl_rad1 for precomputed characteristic value
  8336. Computes the oblate spheroidal radial function of the first kind
  8337. and its derivative (with respect to `x`) for mode parameters m>=0
  8338. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``. Requires
  8339. pre-computed characteristic value.
  8340. Parameters
  8341. ----------
  8342. m : array_like
  8343. Mode parameter m (nonnegative)
  8344. n : array_like
  8345. Mode parameter n (>= m)
  8346. c : array_like
  8347. Spheroidal parameter
  8348. cv : array_like
  8349. Characteristic value
  8350. x : array_like
  8351. Parameter x (``|x| < 1.0``)
  8352. out : ndarray, optional
  8353. Optional output array for the function results
  8354. Returns
  8355. -------
  8356. s : scalar or ndarray
  8357. Value of the function
  8358. sp : scalar or ndarray
  8359. Value of the derivative vs x
  8360. See Also
  8361. --------
  8362. obl_rad1
  8363. """)
  8364. add_newdoc("obl_rad2",
  8365. """
  8366. obl_rad2(m, n, c, x, out=None)
  8367. Oblate spheroidal radial function of the second kind and its derivative.
  8368. Computes the oblate spheroidal radial function of the second kind
  8369. and its derivative (with respect to `x`) for mode parameters m>=0
  8370. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``.
  8371. Parameters
  8372. ----------
  8373. m : array_like
  8374. Mode parameter m (nonnegative)
  8375. n : array_like
  8376. Mode parameter n (>= m)
  8377. c : array_like
  8378. Spheroidal parameter
  8379. x : array_like
  8380. Parameter x (``|x| < 1.0``)
  8381. out : ndarray, optional
  8382. Optional output array for the function results
  8383. Returns
  8384. -------
  8385. s : scalar or ndarray
  8386. Value of the function
  8387. sp : scalar or ndarray
  8388. Value of the derivative vs x
  8389. See Also
  8390. --------
  8391. obl_rad2_cv
  8392. """)
  8393. add_newdoc("obl_rad2_cv",
  8394. """
  8395. obl_rad2_cv(m, n, c, cv, x, out=None)
  8396. Oblate spheroidal radial function obl_rad2 for precomputed characteristic value
  8397. Computes the oblate spheroidal radial function of the second kind
  8398. and its derivative (with respect to `x`) for mode parameters m>=0
  8399. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``. Requires
  8400. pre-computed characteristic value.
  8401. Parameters
  8402. ----------
  8403. m : array_like
  8404. Mode parameter m (nonnegative)
  8405. n : array_like
  8406. Mode parameter n (>= m)
  8407. c : array_like
  8408. Spheroidal parameter
  8409. cv : array_like
  8410. Characteristic value
  8411. x : array_like
  8412. Parameter x (``|x| < 1.0``)
  8413. out : ndarray, optional
  8414. Optional output array for the function results
  8415. Returns
  8416. -------
  8417. s : scalar or ndarray
  8418. Value of the function
  8419. sp : scalar or ndarray
  8420. Value of the derivative vs x
  8421. See Also
  8422. --------
  8423. obl_rad2
  8424. """)
  8425. add_newdoc("pbdv",
  8426. """
  8427. pbdv(v, x, out=None)
  8428. Parabolic cylinder function D
  8429. Returns (d, dp) the parabolic cylinder function Dv(x) in d and the
  8430. derivative, Dv'(x) in dp.
  8431. Parameters
  8432. ----------
  8433. v : array_like
  8434. Real parameter
  8435. x : array_like
  8436. Real argument
  8437. out : ndarray, optional
  8438. Optional output array for the function results
  8439. Returns
  8440. -------
  8441. d : scalar or ndarray
  8442. Value of the function
  8443. dp : scalar or ndarray
  8444. Value of the derivative vs x
  8445. """)
  8446. add_newdoc("pbvv",
  8447. """
  8448. pbvv(v, x, out=None)
  8449. Parabolic cylinder function V
  8450. Returns the parabolic cylinder function Vv(x) in v and the
  8451. derivative, Vv'(x) in vp.
  8452. Parameters
  8453. ----------
  8454. v : array_like
  8455. Real parameter
  8456. x : array_like
  8457. Real argument
  8458. out : ndarray, optional
  8459. Optional output array for the function results
  8460. Returns
  8461. -------
  8462. v : scalar or ndarray
  8463. Value of the function
  8464. vp : scalar or ndarray
  8465. Value of the derivative vs x
  8466. """)
  8467. add_newdoc("pbwa",
  8468. r"""
  8469. pbwa(a, x, out=None)
  8470. Parabolic cylinder function W.
  8471. The function is a particular solution to the differential equation
  8472. .. math::
  8473. y'' + \left(\frac{1}{4}x^2 - a\right)y = 0,
  8474. for a full definition see section 12.14 in [1]_.
  8475. Parameters
  8476. ----------
  8477. a : array_like
  8478. Real parameter
  8479. x : array_like
  8480. Real argument
  8481. out : ndarray, optional
  8482. Optional output array for the function results
  8483. Returns
  8484. -------
  8485. w : scalar or ndarray
  8486. Value of the function
  8487. wp : scalar or ndarray
  8488. Value of the derivative in x
  8489. Notes
  8490. -----
  8491. The function is a wrapper for a Fortran routine by Zhang and Jin
  8492. [2]_. The implementation is accurate only for ``|a|, |x| < 5`` and
  8493. returns NaN outside that range.
  8494. References
  8495. ----------
  8496. .. [1] Digital Library of Mathematical Functions, 14.30.
  8497. https://dlmf.nist.gov/14.30
  8498. .. [2] Zhang, Shanjie and Jin, Jianming. "Computation of Special
  8499. Functions", John Wiley and Sons, 1996.
  8500. https://people.sc.fsu.edu/~jburkardt/f_src/special_functions/special_functions.html
  8501. """)
  8502. add_newdoc("pdtr",
  8503. r"""
  8504. pdtr(k, m, out=None)
  8505. Poisson cumulative distribution function.
  8506. Defined as the probability that a Poisson-distributed random
  8507. variable with event rate :math:`m` is less than or equal to
  8508. :math:`k`. More concretely, this works out to be [1]_
  8509. .. math::
  8510. \exp(-m) \sum_{j = 0}^{\lfloor{k}\rfloor} \frac{m^j}{j!}.
  8511. Parameters
  8512. ----------
  8513. k : array_like
  8514. Number of occurrences (nonnegative, real)
  8515. m : array_like
  8516. Shape parameter (nonnegative, real)
  8517. out : ndarray, optional
  8518. Optional output array for the function results
  8519. Returns
  8520. -------
  8521. scalar or ndarray
  8522. Values of the Poisson cumulative distribution function
  8523. See Also
  8524. --------
  8525. pdtrc : Poisson survival function
  8526. pdtrik : inverse of `pdtr` with respect to `k`
  8527. pdtri : inverse of `pdtr` with respect to `m`
  8528. References
  8529. ----------
  8530. .. [1] https://en.wikipedia.org/wiki/Poisson_distribution
  8531. Examples
  8532. --------
  8533. >>> import numpy as np
  8534. >>> import scipy.special as sc
  8535. It is a cumulative distribution function, so it converges to 1
  8536. monotonically as `k` goes to infinity.
  8537. >>> sc.pdtr([1, 10, 100, np.inf], 1)
  8538. array([0.73575888, 0.99999999, 1. , 1. ])
  8539. It is discontinuous at integers and constant between integers.
  8540. >>> sc.pdtr([1, 1.5, 1.9, 2], 1)
  8541. array([0.73575888, 0.73575888, 0.73575888, 0.9196986 ])
  8542. """)
  8543. add_newdoc("pdtrc",
  8544. """
  8545. pdtrc(k, m, out=None)
  8546. Poisson survival function
  8547. Returns the sum of the terms from k+1 to infinity of the Poisson
  8548. distribution: sum(exp(-m) * m**j / j!, j=k+1..inf) = gammainc(
  8549. k+1, m). Arguments must both be non-negative doubles.
  8550. Parameters
  8551. ----------
  8552. k : array_like
  8553. Number of occurrences (nonnegative, real)
  8554. m : array_like
  8555. Shape parameter (nonnegative, real)
  8556. out : ndarray, optional
  8557. Optional output array for the function results
  8558. Returns
  8559. -------
  8560. scalar or ndarray
  8561. Values of the Poisson survival function
  8562. See Also
  8563. --------
  8564. pdtr : Poisson cumulative distribution function
  8565. pdtrik : inverse of `pdtr` with respect to `k`
  8566. pdtri : inverse of `pdtr` with respect to `m`
  8567. """)
  8568. add_newdoc("pdtri",
  8569. """
  8570. pdtri(k, y, out=None)
  8571. Inverse to `pdtr` vs m
  8572. Returns the Poisson variable `m` such that the sum from 0 to `k` of
  8573. the Poisson density is equal to the given probability `y`:
  8574. calculated by ``gammaincinv(k + 1, y)``. `k` must be a nonnegative
  8575. integer and `y` between 0 and 1.
  8576. Parameters
  8577. ----------
  8578. k : array_like
  8579. Number of occurrences (nonnegative, real)
  8580. y : array_like
  8581. Probability
  8582. out : ndarray, optional
  8583. Optional output array for the function results
  8584. Returns
  8585. -------
  8586. scalar or ndarray
  8587. Values of the shape paramter `m` such that ``pdtr(k, m) = p``
  8588. See Also
  8589. --------
  8590. pdtr : Poisson cumulative distribution function
  8591. pdtrc : Poisson survival function
  8592. pdtrik : inverse of `pdtr` with respect to `k`
  8593. """)
  8594. add_newdoc("pdtrik",
  8595. """
  8596. pdtrik(p, m, out=None)
  8597. Inverse to `pdtr` vs `m`.
  8598. Parameters
  8599. ----------
  8600. m : array_like
  8601. Shape parameter (nonnegative, real)
  8602. p : array_like
  8603. Probability
  8604. out : ndarray, optional
  8605. Optional output array for the function results
  8606. Returns
  8607. -------
  8608. scalar or ndarray
  8609. The number of occurrences `k` such that ``pdtr(k, m) = p``
  8610. See Also
  8611. --------
  8612. pdtr : Poisson cumulative distribution function
  8613. pdtrc : Poisson survival function
  8614. pdtri : inverse of `pdtr` with respect to `m`
  8615. """)
  8616. add_newdoc("poch",
  8617. r"""
  8618. poch(z, m, out=None)
  8619. Pochhammer symbol.
  8620. The Pochhammer symbol (rising factorial) is defined as
  8621. .. math::
  8622. (z)_m = \frac{\Gamma(z + m)}{\Gamma(z)}
  8623. For positive integer `m` it reads
  8624. .. math::
  8625. (z)_m = z (z + 1) ... (z + m - 1)
  8626. See [dlmf]_ for more details.
  8627. Parameters
  8628. ----------
  8629. z, m : array_like
  8630. Real-valued arguments.
  8631. out : ndarray, optional
  8632. Optional output array for the function results
  8633. Returns
  8634. -------
  8635. scalar or ndarray
  8636. The value of the function.
  8637. References
  8638. ----------
  8639. .. [dlmf] Nist, Digital Library of Mathematical Functions
  8640. https://dlmf.nist.gov/5.2#iii
  8641. Examples
  8642. --------
  8643. >>> import scipy.special as sc
  8644. It is 1 when m is 0.
  8645. >>> sc.poch([1, 2, 3, 4], 0)
  8646. array([1., 1., 1., 1.])
  8647. For z equal to 1 it reduces to the factorial function.
  8648. >>> sc.poch(1, 5)
  8649. 120.0
  8650. >>> 1 * 2 * 3 * 4 * 5
  8651. 120
  8652. It can be expressed in terms of the gamma function.
  8653. >>> z, m = 3.7, 2.1
  8654. >>> sc.poch(z, m)
  8655. 20.529581933776953
  8656. >>> sc.gamma(z + m) / sc.gamma(z)
  8657. 20.52958193377696
  8658. """)
  8659. add_newdoc("powm1", """
  8660. powm1(x, y, out=None)
  8661. Computes ``x**y - 1``.
  8662. This function is useful when `y` is near 0, or when `x` is near 1.
  8663. The function is implemented for real types only (unlike ``numpy.power``,
  8664. which accepts complex inputs).
  8665. Parameters
  8666. ----------
  8667. x : array_like
  8668. The base. Must be a real type (i.e. integer or float, not complex).
  8669. y : array_like
  8670. The exponent. Must be a real type (i.e. integer or float, not complex).
  8671. Returns
  8672. -------
  8673. array_like
  8674. Result of the calculation
  8675. Notes
  8676. -----
  8677. .. versionadded:: 1.10.0
  8678. The underlying code is implemented for single precision and double
  8679. precision floats only. Unlike `numpy.power`, integer inputs to
  8680. `powm1` are converted to floating point, and complex inputs are
  8681. not accepted.
  8682. Note the following edge cases:
  8683. * ``powm1(x, 0)`` returns 0 for any ``x``, including 0, ``inf``
  8684. and ``nan``.
  8685. * ``powm1(1, y)`` returns 0 for any ``y``, including ``nan``
  8686. and ``inf``.
  8687. Examples
  8688. --------
  8689. >>> import numpy as np
  8690. >>> from scipy.special import powm1
  8691. >>> x = np.array([1.2, 10.0, 0.9999999975])
  8692. >>> y = np.array([1e-9, 1e-11, 0.1875])
  8693. >>> powm1(x, y)
  8694. array([ 1.82321557e-10, 2.30258509e-11, -4.68749998e-10])
  8695. It can be verified that the relative errors in those results
  8696. are less than 2.5e-16.
  8697. Compare that to the result of ``x**y - 1``, where the
  8698. relative errors are all larger than 8e-8:
  8699. >>> x**y - 1
  8700. array([ 1.82321491e-10, 2.30258035e-11, -4.68750039e-10])
  8701. """)
  8702. add_newdoc("pro_ang1",
  8703. """
  8704. pro_ang1(m, n, c, x, out=None)
  8705. Prolate spheroidal angular function of the first kind and its derivative
  8706. Computes the prolate spheroidal angular function of the first kind
  8707. and its derivative (with respect to `x`) for mode parameters m>=0
  8708. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``.
  8709. Parameters
  8710. ----------
  8711. m : array_like
  8712. Nonnegative mode parameter m
  8713. n : array_like
  8714. Mode parameter n (>= m)
  8715. c : array_like
  8716. Spheroidal parameter
  8717. x : array_like
  8718. Real parameter (``|x| < 1.0``)
  8719. out : ndarray, optional
  8720. Optional output array for the function results
  8721. Returns
  8722. -------
  8723. s : scalar or ndarray
  8724. Value of the function
  8725. sp : scalar or ndarray
  8726. Value of the derivative vs x
  8727. """)
  8728. add_newdoc("pro_ang1_cv",
  8729. """
  8730. pro_ang1_cv(m, n, c, cv, x, out=None)
  8731. Prolate spheroidal angular function pro_ang1 for precomputed characteristic value
  8732. Computes the prolate spheroidal angular function of the first kind
  8733. and its derivative (with respect to `x`) for mode parameters m>=0
  8734. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``. Requires
  8735. pre-computed characteristic value.
  8736. Parameters
  8737. ----------
  8738. m : array_like
  8739. Nonnegative mode parameter m
  8740. n : array_like
  8741. Mode parameter n (>= m)
  8742. c : array_like
  8743. Spheroidal parameter
  8744. cv : array_like
  8745. Characteristic value
  8746. x : array_like
  8747. Real parameter (``|x| < 1.0``)
  8748. out : ndarray, optional
  8749. Optional output array for the function results
  8750. Returns
  8751. -------
  8752. s : scalar or ndarray
  8753. Value of the function
  8754. sp : scalar or ndarray
  8755. Value of the derivative vs x
  8756. """)
  8757. add_newdoc("pro_cv",
  8758. """
  8759. pro_cv(m, n, c, out=None)
  8760. Characteristic value of prolate spheroidal function
  8761. Computes the characteristic value of prolate spheroidal wave
  8762. functions of order `m`, `n` (n>=m) and spheroidal parameter `c`.
  8763. Parameters
  8764. ----------
  8765. m : array_like
  8766. Nonnegative mode parameter m
  8767. n : array_like
  8768. Mode parameter n (>= m)
  8769. c : array_like
  8770. Spheroidal parameter
  8771. out : ndarray, optional
  8772. Optional output array for the function results
  8773. Returns
  8774. -------
  8775. cv : scalar or ndarray
  8776. Characteristic value
  8777. """)
  8778. add_newdoc("pro_rad1",
  8779. """
  8780. pro_rad1(m, n, c, x, out=None)
  8781. Prolate spheroidal radial function of the first kind and its derivative
  8782. Computes the prolate spheroidal radial function of the first kind
  8783. and its derivative (with respect to `x`) for mode parameters m>=0
  8784. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``.
  8785. Parameters
  8786. ----------
  8787. m : array_like
  8788. Nonnegative mode parameter m
  8789. n : array_like
  8790. Mode parameter n (>= m)
  8791. c : array_like
  8792. Spheroidal parameter
  8793. x : array_like
  8794. Real parameter (``|x| < 1.0``)
  8795. out : ndarray, optional
  8796. Optional output array for the function results
  8797. Returns
  8798. -------
  8799. s : scalar or ndarray
  8800. Value of the function
  8801. sp : scalar or ndarray
  8802. Value of the derivative vs x
  8803. """)
  8804. add_newdoc("pro_rad1_cv",
  8805. """
  8806. pro_rad1_cv(m, n, c, cv, x, out=None)
  8807. Prolate spheroidal radial function pro_rad1 for precomputed characteristic value
  8808. Computes the prolate spheroidal radial function of the first kind
  8809. and its derivative (with respect to `x`) for mode parameters m>=0
  8810. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``. Requires
  8811. pre-computed characteristic value.
  8812. Parameters
  8813. ----------
  8814. m : array_like
  8815. Nonnegative mode parameter m
  8816. n : array_like
  8817. Mode parameter n (>= m)
  8818. c : array_like
  8819. Spheroidal parameter
  8820. cv : array_like
  8821. Characteristic value
  8822. x : array_like
  8823. Real parameter (``|x| < 1.0``)
  8824. out : ndarray, optional
  8825. Optional output array for the function results
  8826. Returns
  8827. -------
  8828. s : scalar or ndarray
  8829. Value of the function
  8830. sp : scalar or ndarray
  8831. Value of the derivative vs x
  8832. """)
  8833. add_newdoc("pro_rad2",
  8834. """
  8835. pro_rad2(m, n, c, x, out=None)
  8836. Prolate spheroidal radial function of the second kind and its derivative
  8837. Computes the prolate spheroidal radial function of the second kind
  8838. and its derivative (with respect to `x`) for mode parameters m>=0
  8839. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``.
  8840. Parameters
  8841. ----------
  8842. m : array_like
  8843. Nonnegative mode parameter m
  8844. n : array_like
  8845. Mode parameter n (>= m)
  8846. c : array_like
  8847. Spheroidal parameter
  8848. cv : array_like
  8849. Characteristic value
  8850. x : array_like
  8851. Real parameter (``|x| < 1.0``)
  8852. out : ndarray, optional
  8853. Optional output array for the function results
  8854. Returns
  8855. -------
  8856. s : scalar or ndarray
  8857. Value of the function
  8858. sp : scalar or ndarray
  8859. Value of the derivative vs x
  8860. """)
  8861. add_newdoc("pro_rad2_cv",
  8862. """
  8863. pro_rad2_cv(m, n, c, cv, x, out=None)
  8864. Prolate spheroidal radial function pro_rad2 for precomputed characteristic value
  8865. Computes the prolate spheroidal radial function of the second kind
  8866. and its derivative (with respect to `x`) for mode parameters m>=0
  8867. and n>=m, spheroidal parameter `c` and ``|x| < 1.0``. Requires
  8868. pre-computed characteristic value.
  8869. Parameters
  8870. ----------
  8871. m : array_like
  8872. Nonnegative mode parameter m
  8873. n : array_like
  8874. Mode parameter n (>= m)
  8875. c : array_like
  8876. Spheroidal parameter
  8877. cv : array_like
  8878. Characteristic value
  8879. x : array_like
  8880. Real parameter (``|x| < 1.0``)
  8881. out : ndarray, optional
  8882. Optional output array for the function results
  8883. Returns
  8884. -------
  8885. s : scalar or ndarray
  8886. Value of the function
  8887. sp : scalar or ndarray
  8888. Value of the derivative vs x
  8889. """)
  8890. add_newdoc("pseudo_huber",
  8891. r"""
  8892. pseudo_huber(delta, r, out=None)
  8893. Pseudo-Huber loss function.
  8894. .. math:: \mathrm{pseudo\_huber}(\delta, r) = \delta^2 \left( \sqrt{ 1 + \left( \frac{r}{\delta} \right)^2 } - 1 \right)
  8895. Parameters
  8896. ----------
  8897. delta : array_like
  8898. Input array, indicating the soft quadratic vs. linear loss changepoint.
  8899. r : array_like
  8900. Input array, possibly representing residuals.
  8901. out : ndarray, optional
  8902. Optional output array for the function results
  8903. Returns
  8904. -------
  8905. res : scalar or ndarray
  8906. The computed Pseudo-Huber loss function values.
  8907. See also
  8908. --------
  8909. huber: Similar function which this function approximates
  8910. Notes
  8911. -----
  8912. Like `huber`, `pseudo_huber` often serves as a robust loss function
  8913. in statistics or machine learning to reduce the influence of outliers.
  8914. Unlike `huber`, `pseudo_huber` is smooth.
  8915. Typically, `r` represents residuals, the difference
  8916. between a model prediction and data. Then, for :math:`|r|\leq\delta`,
  8917. `pseudo_huber` resembles the squared error and for :math:`|r|>\delta` the
  8918. absolute error. This way, the Pseudo-Huber loss often achieves
  8919. a fast convergence in model fitting for small residuals like the squared
  8920. error loss function and still reduces the influence of outliers
  8921. (:math:`|r|>\delta`) like the absolute error loss. As :math:`\delta` is
  8922. the cutoff between squared and absolute error regimes, it has
  8923. to be tuned carefully for each problem. `pseudo_huber` is also
  8924. convex, making it suitable for gradient based optimization. [1]_ [2]_
  8925. .. versionadded:: 0.15.0
  8926. References
  8927. ----------
  8928. .. [1] Hartley, Zisserman, "Multiple View Geometry in Computer Vision".
  8929. 2003. Cambridge University Press. p. 619
  8930. .. [2] Charbonnier et al. "Deterministic edge-preserving regularization
  8931. in computed imaging". 1997. IEEE Trans. Image Processing.
  8932. 6 (2): 298 - 311.
  8933. Examples
  8934. --------
  8935. Import all necessary modules.
  8936. >>> import numpy as np
  8937. >>> from scipy.special import pseudo_huber, huber
  8938. >>> import matplotlib.pyplot as plt
  8939. Calculate the function for ``delta=1`` at ``r=2``.
  8940. >>> pseudo_huber(1., 2.)
  8941. 1.2360679774997898
  8942. Calculate the function at ``r=2`` for different `delta` by providing
  8943. a list or NumPy array for `delta`.
  8944. >>> pseudo_huber([1., 2., 4.], 3.)
  8945. array([2.16227766, 3.21110255, 4. ])
  8946. Calculate the function for ``delta=1`` at several points by providing
  8947. a list or NumPy array for `r`.
  8948. >>> pseudo_huber(2., np.array([1., 1.5, 3., 4.]))
  8949. array([0.47213595, 1. , 3.21110255, 4.94427191])
  8950. The function can be calculated for different `delta` and `r` by
  8951. providing arrays for both with compatible shapes for broadcasting.
  8952. >>> r = np.array([1., 2.5, 8., 10.])
  8953. >>> deltas = np.array([[1.], [5.], [9.]])
  8954. >>> print(r.shape, deltas.shape)
  8955. (4,) (3, 1)
  8956. >>> pseudo_huber(deltas, r)
  8957. array([[ 0.41421356, 1.6925824 , 7.06225775, 9.04987562],
  8958. [ 0.49509757, 2.95084972, 22.16990566, 30.90169944],
  8959. [ 0.49846624, 3.06693762, 27.37435121, 40.08261642]])
  8960. Plot the function for different `delta`.
  8961. >>> x = np.linspace(-4, 4, 500)
  8962. >>> deltas = [1, 2, 3]
  8963. >>> linestyles = ["dashed", "dotted", "dashdot"]
  8964. >>> fig, ax = plt.subplots()
  8965. >>> combined_plot_parameters = list(zip(deltas, linestyles))
  8966. >>> for delta, style in combined_plot_parameters:
  8967. ... ax.plot(x, pseudo_huber(delta, x), label=f"$\delta={delta}$",
  8968. ... ls=style)
  8969. >>> ax.legend(loc="upper center")
  8970. >>> ax.set_xlabel("$x$")
  8971. >>> ax.set_title("Pseudo-Huber loss function $h_{\delta}(x)$")
  8972. >>> ax.set_xlim(-4, 4)
  8973. >>> ax.set_ylim(0, 8)
  8974. >>> plt.show()
  8975. Finally, illustrate the difference between `huber` and `pseudo_huber` by
  8976. plotting them and their gradients with respect to `r`. The plot shows
  8977. that `pseudo_huber` is continuously differentiable while `huber` is not
  8978. at the points :math:`\pm\delta`.
  8979. >>> def huber_grad(delta, x):
  8980. ... grad = np.copy(x)
  8981. ... linear_area = np.argwhere(np.abs(x) > delta)
  8982. ... grad[linear_area]=delta*np.sign(x[linear_area])
  8983. ... return grad
  8984. >>> def pseudo_huber_grad(delta, x):
  8985. ... return x* (1+(x/delta)**2)**(-0.5)
  8986. >>> x=np.linspace(-3, 3, 500)
  8987. >>> delta = 1.
  8988. >>> fig, ax = plt.subplots(figsize=(7, 7))
  8989. >>> ax.plot(x, huber(delta, x), label="Huber", ls="dashed")
  8990. >>> ax.plot(x, huber_grad(delta, x), label="Huber Gradient", ls="dashdot")
  8991. >>> ax.plot(x, pseudo_huber(delta, x), label="Pseudo-Huber", ls="dotted")
  8992. >>> ax.plot(x, pseudo_huber_grad(delta, x), label="Pseudo-Huber Gradient",
  8993. ... ls="solid")
  8994. >>> ax.legend(loc="upper center")
  8995. >>> plt.show()
  8996. """)
  8997. add_newdoc("psi",
  8998. """
  8999. psi(z, out=None)
  9000. The digamma function.
  9001. The logarithmic derivative of the gamma function evaluated at ``z``.
  9002. Parameters
  9003. ----------
  9004. z : array_like
  9005. Real or complex argument.
  9006. out : ndarray, optional
  9007. Array for the computed values of ``psi``.
  9008. Returns
  9009. -------
  9010. digamma : scalar or ndarray
  9011. Computed values of ``psi``.
  9012. Notes
  9013. -----
  9014. For large values not close to the negative real axis, ``psi`` is
  9015. computed using the asymptotic series (5.11.2) from [1]_. For small
  9016. arguments not close to the negative real axis, the recurrence
  9017. relation (5.5.2) from [1]_ is used until the argument is large
  9018. enough to use the asymptotic series. For values close to the
  9019. negative real axis, the reflection formula (5.5.4) from [1]_ is
  9020. used first. Note that ``psi`` has a family of zeros on the
  9021. negative real axis which occur between the poles at nonpositive
  9022. integers. Around the zeros the reflection formula suffers from
  9023. cancellation and the implementation loses precision. The sole
  9024. positive zero and the first negative zero, however, are handled
  9025. separately by precomputing series expansions using [2]_, so the
  9026. function should maintain full accuracy around the origin.
  9027. References
  9028. ----------
  9029. .. [1] NIST Digital Library of Mathematical Functions
  9030. https://dlmf.nist.gov/5
  9031. .. [2] Fredrik Johansson and others.
  9032. "mpmath: a Python library for arbitrary-precision floating-point arithmetic"
  9033. (Version 0.19) http://mpmath.org/
  9034. Examples
  9035. --------
  9036. >>> from scipy.special import psi
  9037. >>> z = 3 + 4j
  9038. >>> psi(z)
  9039. (1.55035981733341+1.0105022091860445j)
  9040. Verify psi(z) = psi(z + 1) - 1/z:
  9041. >>> psi(z + 1) - 1/z
  9042. (1.55035981733341+1.0105022091860445j)
  9043. """)
  9044. add_newdoc("radian",
  9045. """
  9046. radian(d, m, s, out=None)
  9047. Convert from degrees to radians.
  9048. Returns the angle given in (d)egrees, (m)inutes, and (s)econds in
  9049. radians.
  9050. Parameters
  9051. ----------
  9052. d : array_like
  9053. Degrees, can be real-valued.
  9054. m : array_like
  9055. Minutes, can be real-valued.
  9056. s : array_like
  9057. Seconds, can be real-valued.
  9058. out : ndarray, optional
  9059. Optional output array for the function results.
  9060. Returns
  9061. -------
  9062. scalar or ndarray
  9063. Values of the inputs in radians.
  9064. Examples
  9065. --------
  9066. >>> import scipy.special as sc
  9067. There are many ways to specify an angle.
  9068. >>> sc.radian(90, 0, 0)
  9069. 1.5707963267948966
  9070. >>> sc.radian(0, 60 * 90, 0)
  9071. 1.5707963267948966
  9072. >>> sc.radian(0, 0, 60**2 * 90)
  9073. 1.5707963267948966
  9074. The inputs can be real-valued.
  9075. >>> sc.radian(1.5, 0, 0)
  9076. 0.02617993877991494
  9077. >>> sc.radian(1, 30, 0)
  9078. 0.02617993877991494
  9079. """)
  9080. add_newdoc("rel_entr",
  9081. r"""
  9082. rel_entr(x, y, out=None)
  9083. Elementwise function for computing relative entropy.
  9084. .. math::
  9085. \mathrm{rel\_entr}(x, y) =
  9086. \begin{cases}
  9087. x \log(x / y) & x > 0, y > 0 \\
  9088. 0 & x = 0, y \ge 0 \\
  9089. \infty & \text{otherwise}
  9090. \end{cases}
  9091. Parameters
  9092. ----------
  9093. x, y : array_like
  9094. Input arrays
  9095. out : ndarray, optional
  9096. Optional output array for the function results
  9097. Returns
  9098. -------
  9099. scalar or ndarray
  9100. Relative entropy of the inputs
  9101. See Also
  9102. --------
  9103. entr, kl_div, scipy.stats.entropy
  9104. Notes
  9105. -----
  9106. .. versionadded:: 0.15.0
  9107. This function is jointly convex in x and y.
  9108. The origin of this function is in convex programming; see
  9109. [1]_. Given two discrete probability distributions :math:`p_1,
  9110. \ldots, p_n` and :math:`q_1, \ldots, q_n`, the definition of relative
  9111. entropy in the context of *information theory* is
  9112. .. math::
  9113. \sum_{i = 1}^n \mathrm{rel\_entr}(p_i, q_i).
  9114. To compute the latter quantity, use `scipy.stats.entropy`.
  9115. See [2]_ for details.
  9116. References
  9117. ----------
  9118. .. [1] Boyd, Stephen and Lieven Vandenberghe. *Convex optimization*.
  9119. Cambridge University Press, 2004.
  9120. :doi:`https://doi.org/10.1017/CBO9780511804441`
  9121. .. [2] Kullback-Leibler divergence,
  9122. https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence
  9123. """)
  9124. add_newdoc("rgamma",
  9125. r"""
  9126. rgamma(z, out=None)
  9127. Reciprocal of the gamma function.
  9128. Defined as :math:`1 / \Gamma(z)`, where :math:`\Gamma` is the
  9129. gamma function. For more on the gamma function see `gamma`.
  9130. Parameters
  9131. ----------
  9132. z : array_like
  9133. Real or complex valued input
  9134. out : ndarray, optional
  9135. Optional output array for the function results
  9136. Returns
  9137. -------
  9138. scalar or ndarray
  9139. Function results
  9140. Notes
  9141. -----
  9142. The gamma function has no zeros and has simple poles at
  9143. nonpositive integers, so `rgamma` is an entire function with zeros
  9144. at the nonpositive integers. See the discussion in [dlmf]_ for
  9145. more details.
  9146. See Also
  9147. --------
  9148. gamma, gammaln, loggamma
  9149. References
  9150. ----------
  9151. .. [dlmf] Nist, Digital Library of Mathematical functions,
  9152. https://dlmf.nist.gov/5.2#i
  9153. Examples
  9154. --------
  9155. >>> import scipy.special as sc
  9156. It is the reciprocal of the gamma function.
  9157. >>> sc.rgamma([1, 2, 3, 4])
  9158. array([1. , 1. , 0.5 , 0.16666667])
  9159. >>> 1 / sc.gamma([1, 2, 3, 4])
  9160. array([1. , 1. , 0.5 , 0.16666667])
  9161. It is zero at nonpositive integers.
  9162. >>> sc.rgamma([0, -1, -2, -3])
  9163. array([0., 0., 0., 0.])
  9164. It rapidly underflows to zero along the positive real axis.
  9165. >>> sc.rgamma([10, 100, 179])
  9166. array([2.75573192e-006, 1.07151029e-156, 0.00000000e+000])
  9167. """)
  9168. add_newdoc("round",
  9169. """
  9170. round(x, out=None)
  9171. Round to the nearest integer.
  9172. Returns the nearest integer to `x`. If `x` ends in 0.5 exactly,
  9173. the nearest even integer is chosen.
  9174. Parameters
  9175. ----------
  9176. x : array_like
  9177. Real valued input.
  9178. out : ndarray, optional
  9179. Optional output array for the function results.
  9180. Returns
  9181. -------
  9182. scalar or ndarray
  9183. The nearest integers to the elements of `x`. The result is of
  9184. floating type, not integer type.
  9185. Examples
  9186. --------
  9187. >>> import scipy.special as sc
  9188. It rounds to even.
  9189. >>> sc.round([0.5, 1.5])
  9190. array([0., 2.])
  9191. """)
  9192. add_newdoc("shichi",
  9193. r"""
  9194. shichi(x, out=None)
  9195. Hyperbolic sine and cosine integrals.
  9196. The hyperbolic sine integral is
  9197. .. math::
  9198. \int_0^x \frac{\sinh{t}}{t}dt
  9199. and the hyperbolic cosine integral is
  9200. .. math::
  9201. \gamma + \log(x) + \int_0^x \frac{\cosh{t} - 1}{t} dt
  9202. where :math:`\gamma` is Euler's constant and :math:`\log` is the
  9203. principal branch of the logarithm [1]_.
  9204. Parameters
  9205. ----------
  9206. x : array_like
  9207. Real or complex points at which to compute the hyperbolic sine
  9208. and cosine integrals.
  9209. out : tuple of ndarray, optional
  9210. Optional output arrays for the function results
  9211. Returns
  9212. -------
  9213. si : scalar or ndarray
  9214. Hyperbolic sine integral at ``x``
  9215. ci : scalar or ndarray
  9216. Hyperbolic cosine integral at ``x``
  9217. See Also
  9218. --------
  9219. sici : Sine and cosine integrals.
  9220. exp1 : Exponential integral E1.
  9221. expi : Exponential integral Ei.
  9222. Notes
  9223. -----
  9224. For real arguments with ``x < 0``, ``chi`` is the real part of the
  9225. hyperbolic cosine integral. For such points ``chi(x)`` and ``chi(x
  9226. + 0j)`` differ by a factor of ``1j*pi``.
  9227. For real arguments the function is computed by calling Cephes'
  9228. [2]_ *shichi* routine. For complex arguments the algorithm is based
  9229. on Mpmath's [3]_ *shi* and *chi* routines.
  9230. References
  9231. ----------
  9232. .. [1] Milton Abramowitz and Irene A. Stegun, eds.
  9233. Handbook of Mathematical Functions with Formulas,
  9234. Graphs, and Mathematical Tables. New York: Dover, 1972.
  9235. (See Section 5.2.)
  9236. .. [2] Cephes Mathematical Functions Library,
  9237. http://www.netlib.org/cephes/
  9238. .. [3] Fredrik Johansson and others.
  9239. "mpmath: a Python library for arbitrary-precision floating-point
  9240. arithmetic" (Version 0.19) http://mpmath.org/
  9241. Examples
  9242. --------
  9243. >>> import numpy as np
  9244. >>> import matplotlib.pyplot as plt
  9245. >>> from scipy.special import shichi, sici
  9246. `shichi` accepts real or complex input:
  9247. >>> shichi(0.5)
  9248. (0.5069967498196671, -0.05277684495649357)
  9249. >>> shichi(0.5 + 2.5j)
  9250. ((0.11772029666668238+1.831091777729851j),
  9251. (0.29912435887648825+1.7395351121166562j))
  9252. The hyperbolic sine and cosine integrals Shi(z) and Chi(z) are
  9253. related to the sine and cosine integrals Si(z) and Ci(z) by
  9254. * Shi(z) = -i*Si(i*z)
  9255. * Chi(z) = Ci(-i*z) + i*pi/2
  9256. >>> z = 0.25 + 5j
  9257. >>> shi, chi = shichi(z)
  9258. >>> shi, -1j*sici(1j*z)[0] # Should be the same.
  9259. ((-0.04834719325101729+1.5469354086921228j),
  9260. (-0.04834719325101729+1.5469354086921228j))
  9261. >>> chi, sici(-1j*z)[1] + 1j*np.pi/2 # Should be the same.
  9262. ((-0.19568708973868087+1.556276312103824j),
  9263. (-0.19568708973868087+1.556276312103824j))
  9264. Plot the functions evaluated on the real axis:
  9265. >>> xp = np.geomspace(1e-8, 4.0, 250)
  9266. >>> x = np.concatenate((-xp[::-1], xp))
  9267. >>> shi, chi = shichi(x)
  9268. >>> fig, ax = plt.subplots()
  9269. >>> ax.plot(x, shi, label='Shi(x)')
  9270. >>> ax.plot(x, chi, '--', label='Chi(x)')
  9271. >>> ax.set_xlabel('x')
  9272. >>> ax.set_title('Hyperbolic Sine and Cosine Integrals')
  9273. >>> ax.legend(shadow=True, framealpha=1, loc='lower right')
  9274. >>> ax.grid(True)
  9275. >>> plt.show()
  9276. """)
  9277. add_newdoc("sici",
  9278. r"""
  9279. sici(x, out=None)
  9280. Sine and cosine integrals.
  9281. The sine integral is
  9282. .. math::
  9283. \int_0^x \frac{\sin{t}}{t}dt
  9284. and the cosine integral is
  9285. .. math::
  9286. \gamma + \log(x) + \int_0^x \frac{\cos{t} - 1}{t}dt
  9287. where :math:`\gamma` is Euler's constant and :math:`\log` is the
  9288. principal branch of the logarithm [1]_.
  9289. Parameters
  9290. ----------
  9291. x : array_like
  9292. Real or complex points at which to compute the sine and cosine
  9293. integrals.
  9294. out : tuple of ndarray, optional
  9295. Optional output arrays for the function results
  9296. Returns
  9297. -------
  9298. si : scalar or ndarray
  9299. Sine integral at ``x``
  9300. ci : scalar or ndarray
  9301. Cosine integral at ``x``
  9302. See Also
  9303. --------
  9304. shichi : Hyperbolic sine and cosine integrals.
  9305. exp1 : Exponential integral E1.
  9306. expi : Exponential integral Ei.
  9307. Notes
  9308. -----
  9309. For real arguments with ``x < 0``, ``ci`` is the real part of the
  9310. cosine integral. For such points ``ci(x)`` and ``ci(x + 0j)``
  9311. differ by a factor of ``1j*pi``.
  9312. For real arguments the function is computed by calling Cephes'
  9313. [2]_ *sici* routine. For complex arguments the algorithm is based
  9314. on Mpmath's [3]_ *si* and *ci* routines.
  9315. References
  9316. ----------
  9317. .. [1] Milton Abramowitz and Irene A. Stegun, eds.
  9318. Handbook of Mathematical Functions with Formulas,
  9319. Graphs, and Mathematical Tables. New York: Dover, 1972.
  9320. (See Section 5.2.)
  9321. .. [2] Cephes Mathematical Functions Library,
  9322. http://www.netlib.org/cephes/
  9323. .. [3] Fredrik Johansson and others.
  9324. "mpmath: a Python library for arbitrary-precision floating-point
  9325. arithmetic" (Version 0.19) http://mpmath.org/
  9326. Examples
  9327. --------
  9328. >>> import numpy as np
  9329. >>> import matplotlib.pyplot as plt
  9330. >>> from scipy.special import sici, exp1
  9331. `sici` accepts real or complex input:
  9332. >>> sici(2.5)
  9333. (1.7785201734438267, 0.2858711963653835)
  9334. >>> sici(2.5 + 3j)
  9335. ((4.505735874563953+0.06863305018999577j),
  9336. (0.0793644206906966-2.935510262937543j))
  9337. For z in the right half plane, the sine and cosine integrals are
  9338. related to the exponential integral E1 (implemented in SciPy as
  9339. `scipy.special.exp1`) by
  9340. * Si(z) = (E1(i*z) - E1(-i*z))/2i + pi/2
  9341. * Ci(z) = -(E1(i*z) + E1(-i*z))/2
  9342. See [1]_ (equations 5.2.21 and 5.2.23).
  9343. We can verify these relations:
  9344. >>> z = 2 - 3j
  9345. >>> sici(z)
  9346. ((4.54751388956229-1.3991965806460565j),
  9347. (1.408292501520851+2.9836177420296055j))
  9348. >>> (exp1(1j*z) - exp1(-1j*z))/2j + np.pi/2 # Same as sine integral
  9349. (4.54751388956229-1.3991965806460565j)
  9350. >>> -(exp1(1j*z) + exp1(-1j*z))/2 # Same as cosine integral
  9351. (1.408292501520851+2.9836177420296055j)
  9352. Plot the functions evaluated on the real axis; the dotted horizontal
  9353. lines are at pi/2 and -pi/2:
  9354. >>> x = np.linspace(-16, 16, 150)
  9355. >>> si, ci = sici(x)
  9356. >>> fig, ax = plt.subplots()
  9357. >>> ax.plot(x, si, label='Si(x)')
  9358. >>> ax.plot(x, ci, '--', label='Ci(x)')
  9359. >>> ax.legend(shadow=True, framealpha=1, loc='upper left')
  9360. >>> ax.set_xlabel('x')
  9361. >>> ax.set_title('Sine and Cosine Integrals')
  9362. >>> ax.axhline(np.pi/2, linestyle=':', alpha=0.5, color='k')
  9363. >>> ax.axhline(-np.pi/2, linestyle=':', alpha=0.5, color='k')
  9364. >>> ax.grid(True)
  9365. >>> plt.show()
  9366. """)
  9367. add_newdoc("sindg",
  9368. """
  9369. sindg(x, out=None)
  9370. Sine of the angle `x` given in degrees.
  9371. Parameters
  9372. ----------
  9373. x : array_like
  9374. Angle, given in degrees.
  9375. out : ndarray, optional
  9376. Optional output array for the function results.
  9377. Returns
  9378. -------
  9379. scalar or ndarray
  9380. Sine at the input.
  9381. See Also
  9382. --------
  9383. cosdg, tandg, cotdg
  9384. Examples
  9385. --------
  9386. >>> import numpy as np
  9387. >>> import scipy.special as sc
  9388. It is more accurate than using sine directly.
  9389. >>> x = 180 * np.arange(3)
  9390. >>> sc.sindg(x)
  9391. array([ 0., -0., 0.])
  9392. >>> np.sin(x * np.pi / 180)
  9393. array([ 0.0000000e+00, 1.2246468e-16, -2.4492936e-16])
  9394. """)
  9395. add_newdoc("smirnov",
  9396. r"""
  9397. smirnov(n, d, out=None)
  9398. Kolmogorov-Smirnov complementary cumulative distribution function
  9399. Returns the exact Kolmogorov-Smirnov complementary cumulative
  9400. distribution function,(aka the Survival Function) of Dn+ (or Dn-)
  9401. for a one-sided test of equality between an empirical and a
  9402. theoretical distribution. It is equal to the probability that the
  9403. maximum difference between a theoretical distribution and an empirical
  9404. one based on `n` samples is greater than d.
  9405. Parameters
  9406. ----------
  9407. n : int
  9408. Number of samples
  9409. d : float array_like
  9410. Deviation between the Empirical CDF (ECDF) and the target CDF.
  9411. out : ndarray, optional
  9412. Optional output array for the function results
  9413. Returns
  9414. -------
  9415. scalar or ndarray
  9416. The value(s) of smirnov(n, d), Prob(Dn+ >= d) (Also Prob(Dn- >= d))
  9417. See Also
  9418. --------
  9419. smirnovi : The Inverse Survival Function for the distribution
  9420. scipy.stats.ksone : Provides the functionality as a continuous distribution
  9421. kolmogorov, kolmogi : Functions for the two-sided distribution
  9422. Notes
  9423. -----
  9424. `smirnov` is used by `stats.kstest` in the application of the
  9425. Kolmogorov-Smirnov Goodness of Fit test. For historial reasons this
  9426. function is exposed in `scpy.special`, but the recommended way to achieve
  9427. the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
  9428. `stats.ksone` distribution.
  9429. Examples
  9430. --------
  9431. >>> import numpy as np
  9432. >>> from scipy.special import smirnov
  9433. >>> from scipy.stats import norm
  9434. Show the probability of a gap at least as big as 0, 0.5 and 1.0 for a
  9435. sample of size 5.
  9436. >>> smirnov(5, [0, 0.5, 1.0])
  9437. array([ 1. , 0.056, 0. ])
  9438. Compare a sample of size 5 against N(0, 1), the standard normal
  9439. distribution with mean 0 and standard deviation 1.
  9440. `x` is the sample.
  9441. >>> x = np.array([-1.392, -0.135, 0.114, 0.190, 1.82])
  9442. >>> target = norm(0, 1)
  9443. >>> cdfs = target.cdf(x)
  9444. >>> cdfs
  9445. array([0.0819612 , 0.44630594, 0.5453811 , 0.57534543, 0.9656205 ])
  9446. Construct the empirical CDF and the K-S statistics (Dn+, Dn-, Dn).
  9447. >>> n = len(x)
  9448. >>> ecdfs = np.arange(n+1, dtype=float)/n
  9449. >>> cols = np.column_stack([x, ecdfs[1:], cdfs, cdfs - ecdfs[:n],
  9450. ... ecdfs[1:] - cdfs])
  9451. >>> with np.printoptions(precision=3):
  9452. ... print(cols)
  9453. [[-1.392 0.2 0.082 0.082 0.118]
  9454. [-0.135 0.4 0.446 0.246 -0.046]
  9455. [ 0.114 0.6 0.545 0.145 0.055]
  9456. [ 0.19 0.8 0.575 -0.025 0.225]
  9457. [ 1.82 1. 0.966 0.166 0.034]]
  9458. >>> gaps = cols[:, -2:]
  9459. >>> Dnpm = np.max(gaps, axis=0)
  9460. >>> print(f'Dn-={Dnpm[0]:f}, Dn+={Dnpm[1]:f}')
  9461. Dn-=0.246306, Dn+=0.224655
  9462. >>> probs = smirnov(n, Dnpm)
  9463. >>> print(f'For a sample of size {n} drawn from N(0, 1):',
  9464. ... f' Smirnov n={n}: Prob(Dn- >= {Dnpm[0]:f}) = {probs[0]:.4f}',
  9465. ... f' Smirnov n={n}: Prob(Dn+ >= {Dnpm[1]:f}) = {probs[1]:.4f}',
  9466. ... sep='\n')
  9467. For a sample of size 5 drawn from N(0, 1):
  9468. Smirnov n=5: Prob(Dn- >= 0.246306) = 0.4711
  9469. Smirnov n=5: Prob(Dn+ >= 0.224655) = 0.5245
  9470. Plot the empirical CDF and the standard normal CDF.
  9471. >>> import matplotlib.pyplot as plt
  9472. >>> plt.step(np.concatenate(([-2.5], x, [2.5])),
  9473. ... np.concatenate((ecdfs, [1])),
  9474. ... where='post', label='Empirical CDF')
  9475. >>> xx = np.linspace(-2.5, 2.5, 100)
  9476. >>> plt.plot(xx, target.cdf(xx), '--', label='CDF for N(0, 1)')
  9477. Add vertical lines marking Dn+ and Dn-.
  9478. >>> iminus, iplus = np.argmax(gaps, axis=0)
  9479. >>> plt.vlines([x[iminus]], ecdfs[iminus], cdfs[iminus], color='r',
  9480. ... alpha=0.5, lw=4)
  9481. >>> plt.vlines([x[iplus]], cdfs[iplus], ecdfs[iplus+1], color='m',
  9482. ... alpha=0.5, lw=4)
  9483. >>> plt.grid(True)
  9484. >>> plt.legend(framealpha=1, shadow=True)
  9485. >>> plt.show()
  9486. """)
  9487. add_newdoc("smirnovi",
  9488. """
  9489. smirnovi(n, p, out=None)
  9490. Inverse to `smirnov`
  9491. Returns `d` such that ``smirnov(n, d) == p``, the critical value
  9492. corresponding to `p`.
  9493. Parameters
  9494. ----------
  9495. n : int
  9496. Number of samples
  9497. p : float array_like
  9498. Probability
  9499. out : ndarray, optional
  9500. Optional output array for the function results
  9501. Returns
  9502. -------
  9503. scalar or ndarray
  9504. The value(s) of smirnovi(n, p), the critical values.
  9505. See Also
  9506. --------
  9507. smirnov : The Survival Function (SF) for the distribution
  9508. scipy.stats.ksone : Provides the functionality as a continuous distribution
  9509. kolmogorov, kolmogi : Functions for the two-sided distribution
  9510. scipy.stats.kstwobign : Two-sided Kolmogorov-Smirnov distribution, large n
  9511. Notes
  9512. -----
  9513. `smirnov` is used by `stats.kstest` in the application of the
  9514. Kolmogorov-Smirnov Goodness of Fit test. For historial reasons this
  9515. function is exposed in `scpy.special`, but the recommended way to achieve
  9516. the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
  9517. `stats.ksone` distribution.
  9518. Examples
  9519. --------
  9520. >>> from scipy.special import smirnovi, smirnov
  9521. >>> n = 24
  9522. >>> deviations = [0.1, 0.2, 0.3]
  9523. Use `smirnov` to compute the complementary CDF of the Smirnov
  9524. distribution for the given number of samples and deviations.
  9525. >>> p = smirnov(n, deviations)
  9526. >>> p
  9527. array([0.58105083, 0.12826832, 0.01032231])
  9528. The inverse function ``smirnovi(n, p)`` returns ``deviations``.
  9529. >>> smirnovi(n, p)
  9530. array([0.1, 0.2, 0.3])
  9531. """)
  9532. add_newdoc("_smirnovc",
  9533. """
  9534. _smirnovc(n, d)
  9535. Internal function, do not use.
  9536. """)
  9537. add_newdoc("_smirnovci",
  9538. """
  9539. Internal function, do not use.
  9540. """)
  9541. add_newdoc("_smirnovp",
  9542. """
  9543. _smirnovp(n, p)
  9544. Internal function, do not use.
  9545. """)
  9546. add_newdoc("spence",
  9547. r"""
  9548. spence(z, out=None)
  9549. Spence's function, also known as the dilogarithm.
  9550. It is defined to be
  9551. .. math::
  9552. \int_1^z \frac{\log(t)}{1 - t}dt
  9553. for complex :math:`z`, where the contour of integration is taken
  9554. to avoid the branch cut of the logarithm. Spence's function is
  9555. analytic everywhere except the negative real axis where it has a
  9556. branch cut.
  9557. Parameters
  9558. ----------
  9559. z : array_like
  9560. Points at which to evaluate Spence's function
  9561. out : ndarray, optional
  9562. Optional output array for the function results
  9563. Returns
  9564. -------
  9565. s : scalar or ndarray
  9566. Computed values of Spence's function
  9567. Notes
  9568. -----
  9569. There is a different convention which defines Spence's function by
  9570. the integral
  9571. .. math::
  9572. -\int_0^z \frac{\log(1 - t)}{t}dt;
  9573. this is our ``spence(1 - z)``.
  9574. Examples
  9575. --------
  9576. >>> import numpy as np
  9577. >>> from scipy.special import spence
  9578. >>> import matplotlib.pyplot as plt
  9579. The function is defined for complex inputs:
  9580. >>> spence([1-1j, 1.5+2j, 3j, -10-5j])
  9581. array([-0.20561676+0.91596559j, -0.86766909-1.39560134j,
  9582. -0.59422064-2.49129918j, -1.14044398+6.80075924j])
  9583. For complex inputs on the branch cut, which is the negative real axis,
  9584. the function returns the limit for ``z`` with positive imaginary part.
  9585. For example, in the following, note the sign change of the imaginary
  9586. part of the output for ``z = -2`` and ``z = -2 - 1e-8j``:
  9587. >>> spence([-2 + 1e-8j, -2, -2 - 1e-8j])
  9588. array([2.32018041-3.45139229j, 2.32018042-3.4513923j ,
  9589. 2.32018041+3.45139229j])
  9590. The function returns ``nan`` for real inputs on the branch cut:
  9591. >>> spence(-1.5)
  9592. nan
  9593. Verify some particular values: ``spence(0) = pi**2/6``,
  9594. ``spence(1) = 0`` and ``spence(2) = -pi**2/12``.
  9595. >>> spence([0, 1, 2])
  9596. array([ 1.64493407, 0. , -0.82246703])
  9597. >>> np.pi**2/6, -np.pi**2/12
  9598. (1.6449340668482264, -0.8224670334241132)
  9599. Verify the identity::
  9600. spence(z) + spence(1 - z) = pi**2/6 - log(z)*log(1 - z)
  9601. >>> z = 3 + 4j
  9602. >>> spence(z) + spence(1 - z)
  9603. (-2.6523186143876067+1.8853470951513935j)
  9604. >>> np.pi**2/6 - np.log(z)*np.log(1 - z)
  9605. (-2.652318614387606+1.885347095151394j)
  9606. Plot the function for positive real input.
  9607. >>> fig, ax = plt.subplots()
  9608. >>> x = np.linspace(0, 6, 400)
  9609. >>> ax.plot(x, spence(x))
  9610. >>> ax.grid()
  9611. >>> ax.set_xlabel('x')
  9612. >>> ax.set_title('spence(x)')
  9613. >>> plt.show()
  9614. """)
  9615. add_newdoc("stdtr",
  9616. """
  9617. stdtr(df, t, out=None)
  9618. Student t distribution cumulative distribution function
  9619. Returns the integral from minus infinity to t of the Student t
  9620. distribution with df > 0 degrees of freedom::
  9621. gamma((df+1)/2)/(sqrt(df*pi)*gamma(df/2)) *
  9622. integral((1+x**2/df)**(-df/2-1/2), x=-inf..t)
  9623. Parameters
  9624. ----------
  9625. df : array_like
  9626. Degrees of freedom
  9627. t : array_like
  9628. Upper bound of the integral
  9629. out : ndarray, optional
  9630. Optional output array for the function results
  9631. Returns
  9632. -------
  9633. scalar or ndarray
  9634. Value of the Student t CDF at t
  9635. See Also
  9636. --------
  9637. stdtridf : inverse of stdtr with respect to `df`
  9638. stdtrit : inverse of stdtr with respect to `t`
  9639. """)
  9640. add_newdoc("stdtridf",
  9641. """
  9642. stdtridf(p, t, out=None)
  9643. Inverse of `stdtr` vs df
  9644. Returns the argument df such that stdtr(df, t) is equal to `p`.
  9645. Parameters
  9646. ----------
  9647. p : array_like
  9648. Probability
  9649. t : array_like
  9650. Upper bound of the integral
  9651. out : ndarray, optional
  9652. Optional output array for the function results
  9653. Returns
  9654. -------
  9655. df : scalar or ndarray
  9656. Value of `df` such that ``stdtr(df, t) == p``
  9657. See Also
  9658. --------
  9659. stdtr : Student t CDF
  9660. stdtrit : inverse of stdtr with respect to `t`
  9661. """)
  9662. add_newdoc("stdtrit",
  9663. """
  9664. stdtrit(df, p, out=None)
  9665. Inverse of `stdtr` vs `t`
  9666. Returns the argument `t` such that stdtr(df, t) is equal to `p`.
  9667. Parameters
  9668. ----------
  9669. df : array_like
  9670. Degrees of freedom
  9671. p : array_like
  9672. Probability
  9673. out : ndarray, optional
  9674. Optional output array for the function results
  9675. Returns
  9676. -------
  9677. t : scalar or ndarray
  9678. Value of `t` such that ``stdtr(df, t) == p``
  9679. See Also
  9680. --------
  9681. stdtr : Student t CDF
  9682. stdtridf : inverse of stdtr with respect to `df`
  9683. """)
  9684. add_newdoc("struve",
  9685. r"""
  9686. struve(v, x, out=None)
  9687. Struve function.
  9688. Return the value of the Struve function of order `v` at `x`. The Struve
  9689. function is defined as,
  9690. .. math::
  9691. H_v(x) = (z/2)^{v + 1} \sum_{n=0}^\infty \frac{(-1)^n (z/2)^{2n}}{\Gamma(n + \frac{3}{2}) \Gamma(n + v + \frac{3}{2})},
  9692. where :math:`\Gamma` is the gamma function.
  9693. Parameters
  9694. ----------
  9695. v : array_like
  9696. Order of the Struve function (float).
  9697. x : array_like
  9698. Argument of the Struve function (float; must be positive unless `v` is
  9699. an integer).
  9700. out : ndarray, optional
  9701. Optional output array for the function results
  9702. Returns
  9703. -------
  9704. H : scalar or ndarray
  9705. Value of the Struve function of order `v` at `x`.
  9706. Notes
  9707. -----
  9708. Three methods discussed in [1]_ are used to evaluate the Struve function:
  9709. - power series
  9710. - expansion in Bessel functions (if :math:`|z| < |v| + 20`)
  9711. - asymptotic large-z expansion (if :math:`z \geq 0.7v + 12`)
  9712. Rounding errors are estimated based on the largest terms in the sums, and
  9713. the result associated with the smallest error is returned.
  9714. See also
  9715. --------
  9716. modstruve: Modified Struve function
  9717. References
  9718. ----------
  9719. .. [1] NIST Digital Library of Mathematical Functions
  9720. https://dlmf.nist.gov/11
  9721. Examples
  9722. --------
  9723. Calculate the Struve function of order 1 at 2.
  9724. >>> import numpy as np
  9725. >>> from scipy.special import struve
  9726. >>> import matplotlib.pyplot as plt
  9727. >>> struve(1, 2.)
  9728. 0.6467637282835622
  9729. Calculate the Struve function at 2 for orders 1, 2 and 3 by providing
  9730. a list for the order parameter `v`.
  9731. >>> struve([1, 2, 3], 2.)
  9732. array([0.64676373, 0.28031806, 0.08363767])
  9733. Calculate the Struve function of order 1 for several points by providing
  9734. an array for `x`.
  9735. >>> points = np.array([2., 5., 8.])
  9736. >>> struve(1, points)
  9737. array([0.64676373, 0.80781195, 0.48811605])
  9738. Compute the Struve function for several orders at several points by
  9739. providing arrays for `v` and `z`. The arrays have to be broadcastable
  9740. to the correct shapes.
  9741. >>> orders = np.array([[1], [2], [3]])
  9742. >>> points.shape, orders.shape
  9743. ((3,), (3, 1))
  9744. >>> struve(orders, points)
  9745. array([[0.64676373, 0.80781195, 0.48811605],
  9746. [0.28031806, 1.56937455, 1.51769363],
  9747. [0.08363767, 1.50872065, 2.98697513]])
  9748. Plot the Struve functions of order 0 to 3 from -10 to 10.
  9749. >>> fig, ax = plt.subplots()
  9750. >>> x = np.linspace(-10., 10., 1000)
  9751. >>> for i in range(4):
  9752. ... ax.plot(x, struve(i, x), label=f'$H_{i!r}$')
  9753. >>> ax.legend(ncol=2)
  9754. >>> ax.set_xlim(-10, 10)
  9755. >>> ax.set_title(r"Struve functions $H_{\nu}$")
  9756. >>> plt.show()
  9757. """)
  9758. add_newdoc("tandg",
  9759. """
  9760. tandg(x, out=None)
  9761. Tangent of angle `x` given in degrees.
  9762. Parameters
  9763. ----------
  9764. x : array_like
  9765. Angle, given in degrees.
  9766. out : ndarray, optional
  9767. Optional output array for the function results.
  9768. Returns
  9769. -------
  9770. scalar or ndarray
  9771. Tangent at the input.
  9772. See Also
  9773. --------
  9774. sindg, cosdg, cotdg
  9775. Examples
  9776. --------
  9777. >>> import numpy as np
  9778. >>> import scipy.special as sc
  9779. It is more accurate than using tangent directly.
  9780. >>> x = 180 * np.arange(3)
  9781. >>> sc.tandg(x)
  9782. array([0., 0., 0.])
  9783. >>> np.tan(x * np.pi / 180)
  9784. array([ 0.0000000e+00, -1.2246468e-16, -2.4492936e-16])
  9785. """)
  9786. add_newdoc("tklmbda",
  9787. """
  9788. tklmbda(x, lmbda, out=None)
  9789. Tukey-Lambda cumulative distribution function
  9790. Parameters
  9791. ----------
  9792. x, lmbda : array_like
  9793. Parameters
  9794. out : ndarray, optional
  9795. Optional output array for the function results
  9796. Returns
  9797. -------
  9798. cdf : scalar or ndarray
  9799. Value of the Tukey-Lambda CDF
  9800. """)
  9801. add_newdoc("wofz",
  9802. """
  9803. wofz(z, out=None)
  9804. Faddeeva function
  9805. Returns the value of the Faddeeva function for complex argument::
  9806. exp(-z**2) * erfc(-i*z)
  9807. Parameters
  9808. ----------
  9809. z : array_like
  9810. complex argument
  9811. out : ndarray, optional
  9812. Optional output array for the function results
  9813. Returns
  9814. -------
  9815. scalar or ndarray
  9816. Value of the Faddeeva function
  9817. See Also
  9818. --------
  9819. dawsn, erf, erfc, erfcx, erfi
  9820. References
  9821. ----------
  9822. .. [1] Steven G. Johnson, Faddeeva W function implementation.
  9823. http://ab-initio.mit.edu/Faddeeva
  9824. Examples
  9825. --------
  9826. >>> import numpy as np
  9827. >>> from scipy import special
  9828. >>> import matplotlib.pyplot as plt
  9829. >>> x = np.linspace(-3, 3)
  9830. >>> z = special.wofz(x)
  9831. >>> plt.plot(x, z.real, label='wofz(x).real')
  9832. >>> plt.plot(x, z.imag, label='wofz(x).imag')
  9833. >>> plt.xlabel('$x$')
  9834. >>> plt.legend(framealpha=1, shadow=True)
  9835. >>> plt.grid(alpha=0.25)
  9836. >>> plt.show()
  9837. """)
  9838. add_newdoc("xlogy",
  9839. """
  9840. xlogy(x, y, out=None)
  9841. Compute ``x*log(y)`` so that the result is 0 if ``x = 0``.
  9842. Parameters
  9843. ----------
  9844. x : array_like
  9845. Multiplier
  9846. y : array_like
  9847. Argument
  9848. out : ndarray, optional
  9849. Optional output array for the function results
  9850. Returns
  9851. -------
  9852. z : scalar or ndarray
  9853. Computed x*log(y)
  9854. Notes
  9855. -----
  9856. .. versionadded:: 0.13.0
  9857. """)
  9858. add_newdoc("xlog1py",
  9859. """
  9860. xlog1py(x, y, out=None)
  9861. Compute ``x*log1p(y)`` so that the result is 0 if ``x = 0``.
  9862. Parameters
  9863. ----------
  9864. x : array_like
  9865. Multiplier
  9866. y : array_like
  9867. Argument
  9868. out : ndarray, optional
  9869. Optional output array for the function results
  9870. Returns
  9871. -------
  9872. z : scalar or ndarray
  9873. Computed x*log1p(y)
  9874. Notes
  9875. -----
  9876. .. versionadded:: 0.13.0
  9877. """)
  9878. add_newdoc("y0",
  9879. r"""
  9880. y0(x, out=None)
  9881. Bessel function of the second kind of order 0.
  9882. Parameters
  9883. ----------
  9884. x : array_like
  9885. Argument (float).
  9886. out : ndarray, optional
  9887. Optional output array for the function results
  9888. Returns
  9889. -------
  9890. Y : scalar or ndarray
  9891. Value of the Bessel function of the second kind of order 0 at `x`.
  9892. Notes
  9893. -----
  9894. The domain is divided into the intervals [0, 5] and (5, infinity). In the
  9895. first interval a rational approximation :math:`R(x)` is employed to
  9896. compute,
  9897. .. math::
  9898. Y_0(x) = R(x) + \frac{2 \log(x) J_0(x)}{\pi},
  9899. where :math:`J_0` is the Bessel function of the first kind of order 0.
  9900. In the second interval, the Hankel asymptotic expansion is employed with
  9901. two rational functions of degree 6/6 and 7/7.
  9902. This function is a wrapper for the Cephes [1]_ routine `y0`.
  9903. See also
  9904. --------
  9905. j0: Bessel function of the first kind of order 0
  9906. yv: Bessel function of the first kind
  9907. References
  9908. ----------
  9909. .. [1] Cephes Mathematical Functions Library,
  9910. http://www.netlib.org/cephes/
  9911. Examples
  9912. --------
  9913. Calculate the function at one point:
  9914. >>> from scipy.special import y0
  9915. >>> y0(1.)
  9916. 0.08825696421567697
  9917. Calculate at several points:
  9918. >>> import numpy as np
  9919. >>> y0(np.array([0.5, 2., 3.]))
  9920. array([-0.44451873, 0.51037567, 0.37685001])
  9921. Plot the function from 0 to 10.
  9922. >>> import matplotlib.pyplot as plt
  9923. >>> fig, ax = plt.subplots()
  9924. >>> x = np.linspace(0., 10., 1000)
  9925. >>> y = y0(x)
  9926. >>> ax.plot(x, y)
  9927. >>> plt.show()
  9928. """)
  9929. add_newdoc("y1",
  9930. """
  9931. y1(x, out=None)
  9932. Bessel function of the second kind of order 1.
  9933. Parameters
  9934. ----------
  9935. x : array_like
  9936. Argument (float).
  9937. out : ndarray, optional
  9938. Optional output array for the function results
  9939. Returns
  9940. -------
  9941. Y : scalar or ndarray
  9942. Value of the Bessel function of the second kind of order 1 at `x`.
  9943. Notes
  9944. -----
  9945. The domain is divided into the intervals [0, 8] and (8, infinity). In the
  9946. first interval a 25 term Chebyshev expansion is used, and computing
  9947. :math:`J_1` (the Bessel function of the first kind) is required. In the
  9948. second, the asymptotic trigonometric representation is employed using two
  9949. rational functions of degree 5/5.
  9950. This function is a wrapper for the Cephes [1]_ routine `y1`.
  9951. See also
  9952. --------
  9953. j1: Bessel function of the first kind of order 1
  9954. yn: Bessel function of the second kind
  9955. yv: Bessel function of the second kind
  9956. References
  9957. ----------
  9958. .. [1] Cephes Mathematical Functions Library,
  9959. http://www.netlib.org/cephes/
  9960. Examples
  9961. --------
  9962. Calculate the function at one point:
  9963. >>> from scipy.special import y1
  9964. >>> y1(1.)
  9965. -0.7812128213002888
  9966. Calculate at several points:
  9967. >>> import numpy as np
  9968. >>> y1(np.array([0.5, 2., 3.]))
  9969. array([-1.47147239, -0.10703243, 0.32467442])
  9970. Plot the function from 0 to 10.
  9971. >>> import matplotlib.pyplot as plt
  9972. >>> fig, ax = plt.subplots()
  9973. >>> x = np.linspace(0., 10., 1000)
  9974. >>> y = y1(x)
  9975. >>> ax.plot(x, y)
  9976. >>> plt.show()
  9977. """)
  9978. add_newdoc("yn",
  9979. r"""
  9980. yn(n, x, out=None)
  9981. Bessel function of the second kind of integer order and real argument.
  9982. Parameters
  9983. ----------
  9984. n : array_like
  9985. Order (integer).
  9986. x : array_like
  9987. Argument (float).
  9988. out : ndarray, optional
  9989. Optional output array for the function results
  9990. Returns
  9991. -------
  9992. Y : scalar or ndarray
  9993. Value of the Bessel function, :math:`Y_n(x)`.
  9994. Notes
  9995. -----
  9996. Wrapper for the Cephes [1]_ routine `yn`.
  9997. The function is evaluated by forward recurrence on `n`, starting with
  9998. values computed by the Cephes routines `y0` and `y1`. If `n = 0` or 1,
  9999. the routine for `y0` or `y1` is called directly.
  10000. See also
  10001. --------
  10002. yv : For real order and real or complex argument.
  10003. y0: faster implementation of this function for order 0
  10004. y1: faster implementation of this function for order 1
  10005. References
  10006. ----------
  10007. .. [1] Cephes Mathematical Functions Library,
  10008. http://www.netlib.org/cephes/
  10009. Examples
  10010. --------
  10011. Evaluate the function of order 0 at one point.
  10012. >>> from scipy.special import yn
  10013. >>> yn(0, 1.)
  10014. 0.08825696421567697
  10015. Evaluate the function at one point for different orders.
  10016. >>> yn(0, 1.), yn(1, 1.), yn(2, 1.)
  10017. (0.08825696421567697, -0.7812128213002888, -1.6506826068162546)
  10018. The evaluation for different orders can be carried out in one call by
  10019. providing a list or NumPy array as argument for the `v` parameter:
  10020. >>> yn([0, 1, 2], 1.)
  10021. array([ 0.08825696, -0.78121282, -1.65068261])
  10022. Evaluate the function at several points for order 0 by providing an
  10023. array for `z`.
  10024. >>> import numpy as np
  10025. >>> points = np.array([0.5, 3., 8.])
  10026. >>> yn(0, points)
  10027. array([-0.44451873, 0.37685001, 0.22352149])
  10028. If `z` is an array, the order parameter `v` must be broadcastable to
  10029. the correct shape if different orders shall be computed in one call.
  10030. To calculate the orders 0 and 1 for an 1D array:
  10031. >>> orders = np.array([[0], [1]])
  10032. >>> orders.shape
  10033. (2, 1)
  10034. >>> yn(orders, points)
  10035. array([[-0.44451873, 0.37685001, 0.22352149],
  10036. [-1.47147239, 0.32467442, -0.15806046]])
  10037. Plot the functions of order 0 to 3 from 0 to 10.
  10038. >>> import matplotlib.pyplot as plt
  10039. >>> fig, ax = plt.subplots()
  10040. >>> x = np.linspace(0., 10., 1000)
  10041. >>> for i in range(4):
  10042. ... ax.plot(x, yn(i, x), label=f'$Y_{i!r}$')
  10043. >>> ax.set_ylim(-3, 1)
  10044. >>> ax.legend()
  10045. >>> plt.show()
  10046. """)
  10047. add_newdoc("yv",
  10048. r"""
  10049. yv(v, z, out=None)
  10050. Bessel function of the second kind of real order and complex argument.
  10051. Parameters
  10052. ----------
  10053. v : array_like
  10054. Order (float).
  10055. z : array_like
  10056. Argument (float or complex).
  10057. out : ndarray, optional
  10058. Optional output array for the function results
  10059. Returns
  10060. -------
  10061. Y : scalar or ndarray
  10062. Value of the Bessel function of the second kind, :math:`Y_v(x)`.
  10063. Notes
  10064. -----
  10065. For positive `v` values, the computation is carried out using the
  10066. AMOS [1]_ `zbesy` routine, which exploits the connection to the Hankel
  10067. Bessel functions :math:`H_v^{(1)}` and :math:`H_v^{(2)}`,
  10068. .. math:: Y_v(z) = \frac{1}{2\imath} (H_v^{(1)} - H_v^{(2)}).
  10069. For negative `v` values the formula,
  10070. .. math:: Y_{-v}(z) = Y_v(z) \cos(\pi v) + J_v(z) \sin(\pi v)
  10071. is used, where :math:`J_v(z)` is the Bessel function of the first kind,
  10072. computed using the AMOS routine `zbesj`. Note that the second term is
  10073. exactly zero for integer `v`; to improve accuracy the second term is
  10074. explicitly omitted for `v` values such that `v = floor(v)`.
  10075. See also
  10076. --------
  10077. yve : :math:`Y_v` with leading exponential behavior stripped off.
  10078. y0: faster implementation of this function for order 0
  10079. y1: faster implementation of this function for order 1
  10080. References
  10081. ----------
  10082. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  10083. of a Complex Argument and Nonnegative Order",
  10084. http://netlib.org/amos/
  10085. Examples
  10086. --------
  10087. Evaluate the function of order 0 at one point.
  10088. >>> from scipy.special import yv
  10089. >>> yv(0, 1.)
  10090. 0.088256964215677
  10091. Evaluate the function at one point for different orders.
  10092. >>> yv(0, 1.), yv(1, 1.), yv(1.5, 1.)
  10093. (0.088256964215677, -0.7812128213002889, -1.102495575160179)
  10094. The evaluation for different orders can be carried out in one call by
  10095. providing a list or NumPy array as argument for the `v` parameter:
  10096. >>> yv([0, 1, 1.5], 1.)
  10097. array([ 0.08825696, -0.78121282, -1.10249558])
  10098. Evaluate the function at several points for order 0 by providing an
  10099. array for `z`.
  10100. >>> import numpy as np
  10101. >>> points = np.array([0.5, 3., 8.])
  10102. >>> yv(0, points)
  10103. array([-0.44451873, 0.37685001, 0.22352149])
  10104. If `z` is an array, the order parameter `v` must be broadcastable to
  10105. the correct shape if different orders shall be computed in one call.
  10106. To calculate the orders 0 and 1 for an 1D array:
  10107. >>> orders = np.array([[0], [1]])
  10108. >>> orders.shape
  10109. (2, 1)
  10110. >>> yv(orders, points)
  10111. array([[-0.44451873, 0.37685001, 0.22352149],
  10112. [-1.47147239, 0.32467442, -0.15806046]])
  10113. Plot the functions of order 0 to 3 from 0 to 10.
  10114. >>> import matplotlib.pyplot as plt
  10115. >>> fig, ax = plt.subplots()
  10116. >>> x = np.linspace(0., 10., 1000)
  10117. >>> for i in range(4):
  10118. ... ax.plot(x, yv(i, x), label=f'$Y_{i!r}$')
  10119. >>> ax.set_ylim(-3, 1)
  10120. >>> ax.legend()
  10121. >>> plt.show()
  10122. """)
  10123. add_newdoc("yve",
  10124. r"""
  10125. yve(v, z, out=None)
  10126. Exponentially scaled Bessel function of the second kind of real order.
  10127. Returns the exponentially scaled Bessel function of the second
  10128. kind of real order `v` at complex `z`::
  10129. yve(v, z) = yv(v, z) * exp(-abs(z.imag))
  10130. Parameters
  10131. ----------
  10132. v : array_like
  10133. Order (float).
  10134. z : array_like
  10135. Argument (float or complex).
  10136. out : ndarray, optional
  10137. Optional output array for the function results
  10138. Returns
  10139. -------
  10140. Y : scalar or ndarray
  10141. Value of the exponentially scaled Bessel function.
  10142. See Also
  10143. --------
  10144. yv: Unscaled Bessel function of the second kind of real order.
  10145. Notes
  10146. -----
  10147. For positive `v` values, the computation is carried out using the
  10148. AMOS [1]_ `zbesy` routine, which exploits the connection to the Hankel
  10149. Bessel functions :math:`H_v^{(1)}` and :math:`H_v^{(2)}`,
  10150. .. math:: Y_v(z) = \frac{1}{2\imath} (H_v^{(1)} - H_v^{(2)}).
  10151. For negative `v` values the formula,
  10152. .. math:: Y_{-v}(z) = Y_v(z) \cos(\pi v) + J_v(z) \sin(\pi v)
  10153. is used, where :math:`J_v(z)` is the Bessel function of the first kind,
  10154. computed using the AMOS routine `zbesj`. Note that the second term is
  10155. exactly zero for integer `v`; to improve accuracy the second term is
  10156. explicitly omitted for `v` values such that `v = floor(v)`.
  10157. Exponentially scaled Bessel functions are useful for large `z`:
  10158. for these, the unscaled Bessel functions can easily under-or overflow.
  10159. References
  10160. ----------
  10161. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  10162. of a Complex Argument and Nonnegative Order",
  10163. http://netlib.org/amos/
  10164. Examples
  10165. --------
  10166. Compare the output of `yv` and `yve` for large complex arguments for `z`
  10167. by computing their values for order ``v=1`` at ``z=1000j``. We see that
  10168. `yv` returns nan but `yve` returns a finite number:
  10169. >>> import numpy as np
  10170. >>> from scipy.special import yv, yve
  10171. >>> v = 1
  10172. >>> z = 1000j
  10173. >>> yv(v, z), yve(v, z)
  10174. ((nan+nanj), (-0.012610930256928629+7.721967686709076e-19j))
  10175. For real arguments for `z`, `yve` returns the same as `yv` up to
  10176. floating point errors.
  10177. >>> v, z = 1, 1000
  10178. >>> yv(v, z), yve(v, z)
  10179. (-0.02478433129235178, -0.02478433129235179)
  10180. The function can be evaluated for several orders at the same time by
  10181. providing a list or NumPy array for `v`:
  10182. >>> yve([1, 2, 3], 1j)
  10183. array([-0.20791042+0.14096627j, 0.38053618-0.04993878j,
  10184. 0.00815531-1.66311097j])
  10185. In the same way, the function can be evaluated at several points in one
  10186. call by providing a list or NumPy array for `z`:
  10187. >>> yve(1, np.array([1j, 2j, 3j]))
  10188. array([-0.20791042+0.14096627j, -0.21526929+0.01205044j,
  10189. -0.19682671+0.00127278j])
  10190. It is also possible to evaluate several orders at several points
  10191. at the same time by providing arrays for `v` and `z` with
  10192. broadcasting compatible shapes. Compute `yve` for two different orders
  10193. `v` and three points `z` resulting in a 2x3 array.
  10194. >>> v = np.array([[1], [2]])
  10195. >>> z = np.array([3j, 4j, 5j])
  10196. >>> v.shape, z.shape
  10197. ((2, 1), (3,))
  10198. >>> yve(v, z)
  10199. array([[-1.96826713e-01+1.27277544e-03j, -1.78750840e-01+1.45558819e-04j,
  10200. -1.63972267e-01+1.73494110e-05j],
  10201. [1.94960056e-03-1.11782545e-01j, 2.02902325e-04-1.17626501e-01j,
  10202. 2.27727687e-05-1.17951906e-01j]])
  10203. """)
  10204. add_newdoc("_zeta",
  10205. """
  10206. _zeta(x, q)
  10207. Internal function, Hurwitz zeta.
  10208. """)
  10209. add_newdoc("zetac",
  10210. """
  10211. zetac(x, out=None)
  10212. Riemann zeta function minus 1.
  10213. This function is defined as
  10214. .. math:: \\zeta(x) = \\sum_{k=2}^{\\infty} 1 / k^x,
  10215. where ``x > 1``. For ``x < 1`` the analytic continuation is
  10216. computed. For more information on the Riemann zeta function, see
  10217. [dlmf]_.
  10218. Parameters
  10219. ----------
  10220. x : array_like of float
  10221. Values at which to compute zeta(x) - 1 (must be real).
  10222. out : ndarray, optional
  10223. Optional output array for the function results
  10224. Returns
  10225. -------
  10226. scalar or ndarray
  10227. Values of zeta(x) - 1.
  10228. See Also
  10229. --------
  10230. zeta
  10231. Examples
  10232. --------
  10233. >>> import numpy as np
  10234. >>> from scipy.special import zetac, zeta
  10235. Some special values:
  10236. >>> zetac(2), np.pi**2/6 - 1
  10237. (0.64493406684822641, 0.6449340668482264)
  10238. >>> zetac(-1), -1.0/12 - 1
  10239. (-1.0833333333333333, -1.0833333333333333)
  10240. Compare ``zetac(x)`` to ``zeta(x) - 1`` for large `x`:
  10241. >>> zetac(60), zeta(60) - 1
  10242. (8.673617380119933e-19, 0.0)
  10243. References
  10244. ----------
  10245. .. [dlmf] NIST Digital Library of Mathematical Functions
  10246. https://dlmf.nist.gov/25
  10247. """)
  10248. add_newdoc("_riemann_zeta",
  10249. """
  10250. Internal function, use `zeta` instead.
  10251. """)
  10252. add_newdoc("_struve_asymp_large_z",
  10253. """
  10254. _struve_asymp_large_z(v, z, is_h)
  10255. Internal function for testing `struve` & `modstruve`
  10256. Evaluates using asymptotic expansion
  10257. Returns
  10258. -------
  10259. v, err
  10260. """)
  10261. add_newdoc("_struve_power_series",
  10262. """
  10263. _struve_power_series(v, z, is_h)
  10264. Internal function for testing `struve` & `modstruve`
  10265. Evaluates using power series
  10266. Returns
  10267. -------
  10268. v, err
  10269. """)
  10270. add_newdoc("_struve_bessel_series",
  10271. """
  10272. _struve_bessel_series(v, z, is_h)
  10273. Internal function for testing `struve` & `modstruve`
  10274. Evaluates using Bessel function series
  10275. Returns
  10276. -------
  10277. v, err
  10278. """)
  10279. add_newdoc("_spherical_jn",
  10280. """
  10281. Internal function, use `spherical_jn` instead.
  10282. """)
  10283. add_newdoc("_spherical_jn_d",
  10284. """
  10285. Internal function, use `spherical_jn` instead.
  10286. """)
  10287. add_newdoc("_spherical_yn",
  10288. """
  10289. Internal function, use `spherical_yn` instead.
  10290. """)
  10291. add_newdoc("_spherical_yn_d",
  10292. """
  10293. Internal function, use `spherical_yn` instead.
  10294. """)
  10295. add_newdoc("_spherical_in",
  10296. """
  10297. Internal function, use `spherical_in` instead.
  10298. """)
  10299. add_newdoc("_spherical_in_d",
  10300. """
  10301. Internal function, use `spherical_in` instead.
  10302. """)
  10303. add_newdoc("_spherical_kn",
  10304. """
  10305. Internal function, use `spherical_kn` instead.
  10306. """)
  10307. add_newdoc("_spherical_kn_d",
  10308. """
  10309. Internal function, use `spherical_kn` instead.
  10310. """)
  10311. add_newdoc("loggamma",
  10312. r"""
  10313. loggamma(z, out=None)
  10314. Principal branch of the logarithm of the gamma function.
  10315. Defined to be :math:`\log(\Gamma(x))` for :math:`x > 0` and
  10316. extended to the complex plane by analytic continuation. The
  10317. function has a single branch cut on the negative real axis.
  10318. .. versionadded:: 0.18.0
  10319. Parameters
  10320. ----------
  10321. z : array_like
  10322. Values in the complex plain at which to compute ``loggamma``
  10323. out : ndarray, optional
  10324. Output array for computed values of ``loggamma``
  10325. Returns
  10326. -------
  10327. loggamma : scalar or ndarray
  10328. Values of ``loggamma`` at z.
  10329. Notes
  10330. -----
  10331. It is not generally true that :math:`\log\Gamma(z) =
  10332. \log(\Gamma(z))`, though the real parts of the functions do
  10333. agree. The benefit of not defining `loggamma` as
  10334. :math:`\log(\Gamma(z))` is that the latter function has a
  10335. complicated branch cut structure whereas `loggamma` is analytic
  10336. except for on the negative real axis.
  10337. The identities
  10338. .. math::
  10339. \exp(\log\Gamma(z)) &= \Gamma(z) \\
  10340. \log\Gamma(z + 1) &= \log(z) + \log\Gamma(z)
  10341. make `loggamma` useful for working in complex logspace.
  10342. On the real line `loggamma` is related to `gammaln` via
  10343. ``exp(loggamma(x + 0j)) = gammasgn(x)*exp(gammaln(x))``, up to
  10344. rounding error.
  10345. The implementation here is based on [hare1997]_.
  10346. See also
  10347. --------
  10348. gammaln : logarithm of the absolute value of the gamma function
  10349. gammasgn : sign of the gamma function
  10350. References
  10351. ----------
  10352. .. [hare1997] D.E.G. Hare,
  10353. *Computing the Principal Branch of log-Gamma*,
  10354. Journal of Algorithms, Volume 25, Issue 2, November 1997, pages 221-236.
  10355. """)
  10356. add_newdoc("_sinpi",
  10357. """
  10358. Internal function, do not use.
  10359. """)
  10360. add_newdoc("_cospi",
  10361. """
  10362. Internal function, do not use.
  10363. """)
  10364. add_newdoc("owens_t",
  10365. """
  10366. owens_t(h, a, out=None)
  10367. Owen's T Function.
  10368. The function T(h, a) gives the probability of the event
  10369. (X > h and 0 < Y < a * X) where X and Y are independent
  10370. standard normal random variables.
  10371. Parameters
  10372. ----------
  10373. h: array_like
  10374. Input value.
  10375. a: array_like
  10376. Input value.
  10377. out : ndarray, optional
  10378. Optional output array for the function results
  10379. Returns
  10380. -------
  10381. t: scalar or ndarray
  10382. Probability of the event (X > h and 0 < Y < a * X),
  10383. where X and Y are independent standard normal random variables.
  10384. Examples
  10385. --------
  10386. >>> from scipy import special
  10387. >>> a = 3.5
  10388. >>> h = 0.78
  10389. >>> special.owens_t(h, a)
  10390. 0.10877216734852274
  10391. References
  10392. ----------
  10393. .. [1] M. Patefield and D. Tandy, "Fast and accurate calculation of
  10394. Owen's T Function", Statistical Software vol. 5, pp. 1-25, 2000.
  10395. """)
  10396. add_newdoc("_factorial",
  10397. """
  10398. Internal function, do not use.
  10399. """)
  10400. add_newdoc("wright_bessel",
  10401. r"""
  10402. wright_bessel(a, b, x, out=None)
  10403. Wright's generalized Bessel function.
  10404. Wright's generalized Bessel function is an entire function and defined as
  10405. .. math:: \Phi(a, b; x) = \sum_{k=0}^\infty \frac{x^k}{k! \Gamma(a k + b)}
  10406. See also [1].
  10407. Parameters
  10408. ----------
  10409. a : array_like of float
  10410. a >= 0
  10411. b : array_like of float
  10412. b >= 0
  10413. x : array_like of float
  10414. x >= 0
  10415. out : ndarray, optional
  10416. Optional output array for the function results
  10417. Returns
  10418. -------
  10419. scalar or ndarray
  10420. Value of the Wright's generalized Bessel function
  10421. Notes
  10422. -----
  10423. Due to the compexity of the function with its three parameters, only
  10424. non-negative arguments are implemented.
  10425. Examples
  10426. --------
  10427. >>> from scipy.special import wright_bessel
  10428. >>> a, b, x = 1.5, 1.1, 2.5
  10429. >>> wright_bessel(a, b-1, x)
  10430. 4.5314465939443025
  10431. Now, let us verify the relation
  10432. .. math:: \Phi(a, b-1; x) = a x \Phi(a, b+a; x) + (b-1) \Phi(a, b; x)
  10433. >>> a * x * wright_bessel(a, b+a, x) + (b-1) * wright_bessel(a, b, x)
  10434. 4.5314465939443025
  10435. References
  10436. ----------
  10437. .. [1] Digital Library of Mathematical Functions, 10.46.
  10438. https://dlmf.nist.gov/10.46.E1
  10439. """)
  10440. add_newdoc("ndtri_exp",
  10441. r"""
  10442. ndtri_exp(y, out=None)
  10443. Inverse of `log_ndtr` vs x. Allows for greater precision than
  10444. `ndtri` composed with `numpy.exp` for very small values of y and for
  10445. y close to 0.
  10446. Parameters
  10447. ----------
  10448. y : array_like of float
  10449. Function argument
  10450. out : ndarray, optional
  10451. Optional output array for the function results
  10452. Returns
  10453. -------
  10454. scalar or ndarray
  10455. Inverse of the log CDF of the standard normal distribution, evaluated
  10456. at y.
  10457. Examples
  10458. --------
  10459. >>> import numpy as np
  10460. >>> import scipy.special as sc
  10461. `ndtri_exp` agrees with the naive implementation when the latter does
  10462. not suffer from underflow.
  10463. >>> sc.ndtri_exp(-1)
  10464. -0.33747496376420244
  10465. >>> sc.ndtri(np.exp(-1))
  10466. -0.33747496376420244
  10467. For extreme values of y, the naive approach fails
  10468. >>> sc.ndtri(np.exp(-800))
  10469. -inf
  10470. >>> sc.ndtri(np.exp(-1e-20))
  10471. inf
  10472. whereas `ndtri_exp` is still able to compute the result to high precision.
  10473. >>> sc.ndtri_exp(-800)
  10474. -39.88469483825668
  10475. >>> sc.ndtri_exp(-1e-20)
  10476. 9.262340089798409
  10477. See Also
  10478. --------
  10479. log_ndtr, ndtri, ndtr
  10480. """)