add_newdocs.py 218 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671
  1. """
  2. This is only meant to add docs to objects defined in C-extension modules.
  3. The purpose is to allow easier editing of the docstrings without
  4. requiring a re-compile.
  5. NOTE: Many of the methods of ndarray have corresponding functions.
  6. If you update these docstrings, please keep also the ones in
  7. core/fromnumeric.py, core/defmatrix.py up-to-date.
  8. """
  9. from __future__ import division, absolute_import, print_function
  10. from numpy.lib import add_newdoc
  11. ###############################################################################
  12. #
  13. # flatiter
  14. #
  15. # flatiter needs a toplevel description
  16. #
  17. ###############################################################################
  18. add_newdoc('numpy.core', 'flatiter',
  19. """
  20. Flat iterator object to iterate over arrays.
  21. A `flatiter` iterator is returned by ``x.flat`` for any array `x`.
  22. It allows iterating over the array as if it were a 1-D array,
  23. either in a for-loop or by calling its `next` method.
  24. Iteration is done in row-major, C-style order (the last
  25. index varying the fastest). The iterator can also be indexed using
  26. basic slicing or advanced indexing.
  27. See Also
  28. --------
  29. ndarray.flat : Return a flat iterator over an array.
  30. ndarray.flatten : Returns a flattened copy of an array.
  31. Notes
  32. -----
  33. A `flatiter` iterator can not be constructed directly from Python code
  34. by calling the `flatiter` constructor.
  35. Examples
  36. --------
  37. >>> x = np.arange(6).reshape(2, 3)
  38. >>> fl = x.flat
  39. >>> type(fl)
  40. <type 'numpy.flatiter'>
  41. >>> for item in fl:
  42. ... print(item)
  43. ...
  44. 0
  45. 1
  46. 2
  47. 3
  48. 4
  49. 5
  50. >>> fl[2:4]
  51. array([2, 3])
  52. """)
  53. # flatiter attributes
  54. add_newdoc('numpy.core', 'flatiter', ('base',
  55. """
  56. A reference to the array that is iterated over.
  57. Examples
  58. --------
  59. >>> x = np.arange(5)
  60. >>> fl = x.flat
  61. >>> fl.base is x
  62. True
  63. """))
  64. add_newdoc('numpy.core', 'flatiter', ('coords',
  65. """
  66. An N-dimensional tuple of current coordinates.
  67. Examples
  68. --------
  69. >>> x = np.arange(6).reshape(2, 3)
  70. >>> fl = x.flat
  71. >>> fl.coords
  72. (0, 0)
  73. >>> fl.next()
  74. 0
  75. >>> fl.coords
  76. (0, 1)
  77. """))
  78. add_newdoc('numpy.core', 'flatiter', ('index',
  79. """
  80. Current flat index into the array.
  81. Examples
  82. --------
  83. >>> x = np.arange(6).reshape(2, 3)
  84. >>> fl = x.flat
  85. >>> fl.index
  86. 0
  87. >>> fl.next()
  88. 0
  89. >>> fl.index
  90. 1
  91. """))
  92. # flatiter functions
  93. add_newdoc('numpy.core', 'flatiter', ('__array__',
  94. """__array__(type=None) Get array from iterator
  95. """))
  96. add_newdoc('numpy.core', 'flatiter', ('copy',
  97. """
  98. copy()
  99. Get a copy of the iterator as a 1-D array.
  100. Examples
  101. --------
  102. >>> x = np.arange(6).reshape(2, 3)
  103. >>> x
  104. array([[0, 1, 2],
  105. [3, 4, 5]])
  106. >>> fl = x.flat
  107. >>> fl.copy()
  108. array([0, 1, 2, 3, 4, 5])
  109. """))
  110. ###############################################################################
  111. #
  112. # nditer
  113. #
  114. ###############################################################################
  115. add_newdoc('numpy.core', 'nditer',
  116. """
  117. Efficient multi-dimensional iterator object to iterate over arrays.
  118. To get started using this object, see the
  119. :ref:`introductory guide to array iteration <arrays.nditer>`.
  120. Parameters
  121. ----------
  122. op : ndarray or sequence of array_like
  123. The array(s) to iterate over.
  124. flags : sequence of str, optional
  125. Flags to control the behavior of the iterator.
  126. * "buffered" enables buffering when required.
  127. * "c_index" causes a C-order index to be tracked.
  128. * "f_index" causes a Fortran-order index to be tracked.
  129. * "multi_index" causes a multi-index, or a tuple of indices
  130. with one per iteration dimension, to be tracked.
  131. * "common_dtype" causes all the operands to be converted to
  132. a common data type, with copying or buffering as necessary.
  133. * "delay_bufalloc" delays allocation of the buffers until
  134. a reset() call is made. Allows "allocate" operands to
  135. be initialized before their values are copied into the buffers.
  136. * "external_loop" causes the `values` given to be
  137. one-dimensional arrays with multiple values instead of
  138. zero-dimensional arrays.
  139. * "grow_inner" allows the `value` array sizes to be made
  140. larger than the buffer size when both "buffered" and
  141. "external_loop" is used.
  142. * "ranged" allows the iterator to be restricted to a sub-range
  143. of the iterindex values.
  144. * "refs_ok" enables iteration of reference types, such as
  145. object arrays.
  146. * "reduce_ok" enables iteration of "readwrite" operands
  147. which are broadcasted, also known as reduction operands.
  148. * "zerosize_ok" allows `itersize` to be zero.
  149. op_flags : list of list of str, optional
  150. This is a list of flags for each operand. At minimum, one of
  151. "readonly", "readwrite", or "writeonly" must be specified.
  152. * "readonly" indicates the operand will only be read from.
  153. * "readwrite" indicates the operand will be read from and written to.
  154. * "writeonly" indicates the operand will only be written to.
  155. * "no_broadcast" prevents the operand from being broadcasted.
  156. * "contig" forces the operand data to be contiguous.
  157. * "aligned" forces the operand data to be aligned.
  158. * "nbo" forces the operand data to be in native byte order.
  159. * "copy" allows a temporary read-only copy if required.
  160. * "updateifcopy" allows a temporary read-write copy if required.
  161. * "allocate" causes the array to be allocated if it is None
  162. in the `op` parameter.
  163. * "no_subtype" prevents an "allocate" operand from using a subtype.
  164. * "arraymask" indicates that this operand is the mask to use
  165. for selecting elements when writing to operands with the
  166. 'writemasked' flag set. The iterator does not enforce this,
  167. but when writing from a buffer back to the array, it only
  168. copies those elements indicated by this mask.
  169. * 'writemasked' indicates that only elements where the chosen
  170. 'arraymask' operand is True will be written to.
  171. op_dtypes : dtype or tuple of dtype(s), optional
  172. The required data type(s) of the operands. If copying or buffering
  173. is enabled, the data will be converted to/from their original types.
  174. order : {'C', 'F', 'A', 'K'}, optional
  175. Controls the iteration order. 'C' means C order, 'F' means
  176. Fortran order, 'A' means 'F' order if all the arrays are Fortran
  177. contiguous, 'C' order otherwise, and 'K' means as close to the
  178. order the array elements appear in memory as possible. This also
  179. affects the element memory order of "allocate" operands, as they
  180. are allocated to be compatible with iteration order.
  181. Default is 'K'.
  182. casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
  183. Controls what kind of data casting may occur when making a copy
  184. or buffering. Setting this to 'unsafe' is not recommended,
  185. as it can adversely affect accumulations.
  186. * 'no' means the data types should not be cast at all.
  187. * 'equiv' means only byte-order changes are allowed.
  188. * 'safe' means only casts which can preserve values are allowed.
  189. * 'same_kind' means only safe casts or casts within a kind,
  190. like float64 to float32, are allowed.
  191. * 'unsafe' means any data conversions may be done.
  192. op_axes : list of list of ints, optional
  193. If provided, is a list of ints or None for each operands.
  194. The list of axes for an operand is a mapping from the dimensions
  195. of the iterator to the dimensions of the operand. A value of
  196. -1 can be placed for entries, causing that dimension to be
  197. treated as "newaxis".
  198. itershape : tuple of ints, optional
  199. The desired shape of the iterator. This allows "allocate" operands
  200. with a dimension mapped by op_axes not corresponding to a dimension
  201. of a different operand to get a value not equal to 1 for that
  202. dimension.
  203. buffersize : int, optional
  204. When buffering is enabled, controls the size of the temporary
  205. buffers. Set to 0 for the default value.
  206. Attributes
  207. ----------
  208. dtypes : tuple of dtype(s)
  209. The data types of the values provided in `value`. This may be
  210. different from the operand data types if buffering is enabled.
  211. finished : bool
  212. Whether the iteration over the operands is finished or not.
  213. has_delayed_bufalloc : bool
  214. If True, the iterator was created with the "delay_bufalloc" flag,
  215. and no reset() function was called on it yet.
  216. has_index : bool
  217. If True, the iterator was created with either the "c_index" or
  218. the "f_index" flag, and the property `index` can be used to
  219. retrieve it.
  220. has_multi_index : bool
  221. If True, the iterator was created with the "multi_index" flag,
  222. and the property `multi_index` can be used to retrieve it.
  223. index :
  224. When the "c_index" or "f_index" flag was used, this property
  225. provides access to the index. Raises a ValueError if accessed
  226. and `has_index` is False.
  227. iterationneedsapi : bool
  228. Whether iteration requires access to the Python API, for example
  229. if one of the operands is an object array.
  230. iterindex : int
  231. An index which matches the order of iteration.
  232. itersize : int
  233. Size of the iterator.
  234. itviews :
  235. Structured view(s) of `operands` in memory, matching the reordered
  236. and optimized iterator access pattern.
  237. multi_index :
  238. When the "multi_index" flag was used, this property
  239. provides access to the index. Raises a ValueError if accessed
  240. accessed and `has_multi_index` is False.
  241. ndim : int
  242. The iterator's dimension.
  243. nop : int
  244. The number of iterator operands.
  245. operands : tuple of operand(s)
  246. The array(s) to be iterated over.
  247. shape : tuple of ints
  248. Shape tuple, the shape of the iterator.
  249. value :
  250. Value of `operands` at current iteration. Normally, this is a
  251. tuple of array scalars, but if the flag "external_loop" is used,
  252. it is a tuple of one dimensional arrays.
  253. Notes
  254. -----
  255. `nditer` supersedes `flatiter`. The iterator implementation behind
  256. `nditer` is also exposed by the Numpy C API.
  257. The Python exposure supplies two iteration interfaces, one which follows
  258. the Python iterator protocol, and another which mirrors the C-style
  259. do-while pattern. The native Python approach is better in most cases, but
  260. if you need the iterator's coordinates or index, use the C-style pattern.
  261. Examples
  262. --------
  263. Here is how we might write an ``iter_add`` function, using the
  264. Python iterator protocol::
  265. def iter_add_py(x, y, out=None):
  266. addop = np.add
  267. it = np.nditer([x, y, out], [],
  268. [['readonly'], ['readonly'], ['writeonly','allocate']])
  269. for (a, b, c) in it:
  270. addop(a, b, out=c)
  271. return it.operands[2]
  272. Here is the same function, but following the C-style pattern::
  273. def iter_add(x, y, out=None):
  274. addop = np.add
  275. it = np.nditer([x, y, out], [],
  276. [['readonly'], ['readonly'], ['writeonly','allocate']])
  277. while not it.finished:
  278. addop(it[0], it[1], out=it[2])
  279. it.iternext()
  280. return it.operands[2]
  281. Here is an example outer product function::
  282. def outer_it(x, y, out=None):
  283. mulop = np.multiply
  284. it = np.nditer([x, y, out], ['external_loop'],
  285. [['readonly'], ['readonly'], ['writeonly', 'allocate']],
  286. op_axes=[range(x.ndim)+[-1]*y.ndim,
  287. [-1]*x.ndim+range(y.ndim),
  288. None])
  289. for (a, b, c) in it:
  290. mulop(a, b, out=c)
  291. return it.operands[2]
  292. >>> a = np.arange(2)+1
  293. >>> b = np.arange(3)+1
  294. >>> outer_it(a,b)
  295. array([[1, 2, 3],
  296. [2, 4, 6]])
  297. Here is an example function which operates like a "lambda" ufunc::
  298. def luf(lamdaexpr, *args, **kwargs):
  299. "luf(lambdaexpr, op1, ..., opn, out=None, order='K', casting='safe', buffersize=0)"
  300. nargs = len(args)
  301. op = (kwargs.get('out',None),) + args
  302. it = np.nditer(op, ['buffered','external_loop'],
  303. [['writeonly','allocate','no_broadcast']] +
  304. [['readonly','nbo','aligned']]*nargs,
  305. order=kwargs.get('order','K'),
  306. casting=kwargs.get('casting','safe'),
  307. buffersize=kwargs.get('buffersize',0))
  308. while not it.finished:
  309. it[0] = lamdaexpr(*it[1:])
  310. it.iternext()
  311. return it.operands[0]
  312. >>> a = np.arange(5)
  313. >>> b = np.ones(5)
  314. >>> luf(lambda i,j:i*i + j/2, a, b)
  315. array([ 0.5, 1.5, 4.5, 9.5, 16.5])
  316. """)
  317. # nditer methods
  318. add_newdoc('numpy.core', 'nditer', ('copy',
  319. """
  320. copy()
  321. Get a copy of the iterator in its current state.
  322. Examples
  323. --------
  324. >>> x = np.arange(10)
  325. >>> y = x + 1
  326. >>> it = np.nditer([x, y])
  327. >>> it.next()
  328. (array(0), array(1))
  329. >>> it2 = it.copy()
  330. >>> it2.next()
  331. (array(1), array(2))
  332. """))
  333. add_newdoc('numpy.core', 'nditer', ('debug_print',
  334. """
  335. debug_print()
  336. Print the current state of the `nditer` instance and debug info to stdout.
  337. """))
  338. add_newdoc('numpy.core', 'nditer', ('enable_external_loop',
  339. """
  340. enable_external_loop()
  341. When the "external_loop" was not used during construction, but
  342. is desired, this modifies the iterator to behave as if the flag
  343. was specified.
  344. """))
  345. add_newdoc('numpy.core', 'nditer', ('iternext',
  346. """
  347. iternext()
  348. Check whether iterations are left, and perform a single internal iteration
  349. without returning the result. Used in the C-style pattern do-while
  350. pattern. For an example, see `nditer`.
  351. Returns
  352. -------
  353. iternext : bool
  354. Whether or not there are iterations left.
  355. """))
  356. add_newdoc('numpy.core', 'nditer', ('remove_axis',
  357. """
  358. remove_axis(i)
  359. Removes axis `i` from the iterator. Requires that the flag "multi_index"
  360. be enabled.
  361. """))
  362. add_newdoc('numpy.core', 'nditer', ('remove_multi_index',
  363. """
  364. remove_multi_index()
  365. When the "multi_index" flag was specified, this removes it, allowing
  366. the internal iteration structure to be optimized further.
  367. """))
  368. add_newdoc('numpy.core', 'nditer', ('reset',
  369. """
  370. reset()
  371. Reset the iterator to its initial state.
  372. """))
  373. ###############################################################################
  374. #
  375. # broadcast
  376. #
  377. ###############################################################################
  378. add_newdoc('numpy.core', 'broadcast',
  379. """
  380. Produce an object that mimics broadcasting.
  381. Parameters
  382. ----------
  383. in1, in2, ... : array_like
  384. Input parameters.
  385. Returns
  386. -------
  387. b : broadcast object
  388. Broadcast the input parameters against one another, and
  389. return an object that encapsulates the result.
  390. Amongst others, it has ``shape`` and ``nd`` properties, and
  391. may be used as an iterator.
  392. Examples
  393. --------
  394. Manually adding two vectors, using broadcasting:
  395. >>> x = np.array([[1], [2], [3]])
  396. >>> y = np.array([4, 5, 6])
  397. >>> b = np.broadcast(x, y)
  398. >>> out = np.empty(b.shape)
  399. >>> out.flat = [u+v for (u,v) in b]
  400. >>> out
  401. array([[ 5., 6., 7.],
  402. [ 6., 7., 8.],
  403. [ 7., 8., 9.]])
  404. Compare against built-in broadcasting:
  405. >>> x + y
  406. array([[5, 6, 7],
  407. [6, 7, 8],
  408. [7, 8, 9]])
  409. """)
  410. # attributes
  411. add_newdoc('numpy.core', 'broadcast', ('index',
  412. """
  413. current index in broadcasted result
  414. Examples
  415. --------
  416. >>> x = np.array([[1], [2], [3]])
  417. >>> y = np.array([4, 5, 6])
  418. >>> b = np.broadcast(x, y)
  419. >>> b.index
  420. 0
  421. >>> b.next(), b.next(), b.next()
  422. ((1, 4), (1, 5), (1, 6))
  423. >>> b.index
  424. 3
  425. """))
  426. add_newdoc('numpy.core', 'broadcast', ('iters',
  427. """
  428. tuple of iterators along ``self``'s "components."
  429. Returns a tuple of `numpy.flatiter` objects, one for each "component"
  430. of ``self``.
  431. See Also
  432. --------
  433. numpy.flatiter
  434. Examples
  435. --------
  436. >>> x = np.array([1, 2, 3])
  437. >>> y = np.array([[4], [5], [6]])
  438. >>> b = np.broadcast(x, y)
  439. >>> row, col = b.iters
  440. >>> row.next(), col.next()
  441. (1, 4)
  442. """))
  443. add_newdoc('numpy.core', 'broadcast', ('nd',
  444. """
  445. Number of dimensions of broadcasted result.
  446. Examples
  447. --------
  448. >>> x = np.array([1, 2, 3])
  449. >>> y = np.array([[4], [5], [6]])
  450. >>> b = np.broadcast(x, y)
  451. >>> b.nd
  452. 2
  453. """))
  454. add_newdoc('numpy.core', 'broadcast', ('numiter',
  455. """
  456. Number of iterators possessed by the broadcasted result.
  457. Examples
  458. --------
  459. >>> x = np.array([1, 2, 3])
  460. >>> y = np.array([[4], [5], [6]])
  461. >>> b = np.broadcast(x, y)
  462. >>> b.numiter
  463. 2
  464. """))
  465. add_newdoc('numpy.core', 'broadcast', ('shape',
  466. """
  467. Shape of broadcasted result.
  468. Examples
  469. --------
  470. >>> x = np.array([1, 2, 3])
  471. >>> y = np.array([[4], [5], [6]])
  472. >>> b = np.broadcast(x, y)
  473. >>> b.shape
  474. (3, 3)
  475. """))
  476. add_newdoc('numpy.core', 'broadcast', ('size',
  477. """
  478. Total size of broadcasted result.
  479. Examples
  480. --------
  481. >>> x = np.array([1, 2, 3])
  482. >>> y = np.array([[4], [5], [6]])
  483. >>> b = np.broadcast(x, y)
  484. >>> b.size
  485. 9
  486. """))
  487. add_newdoc('numpy.core', 'broadcast', ('reset',
  488. """
  489. reset()
  490. Reset the broadcasted result's iterator(s).
  491. Parameters
  492. ----------
  493. None
  494. Returns
  495. -------
  496. None
  497. Examples
  498. --------
  499. >>> x = np.array([1, 2, 3])
  500. >>> y = np.array([[4], [5], [6]]
  501. >>> b = np.broadcast(x, y)
  502. >>> b.index
  503. 0
  504. >>> b.next(), b.next(), b.next()
  505. ((1, 4), (2, 4), (3, 4))
  506. >>> b.index
  507. 3
  508. >>> b.reset()
  509. >>> b.index
  510. 0
  511. """))
  512. ###############################################################################
  513. #
  514. # numpy functions
  515. #
  516. ###############################################################################
  517. add_newdoc('numpy.core.multiarray', 'array',
  518. """
  519. array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
  520. Create an array.
  521. Parameters
  522. ----------
  523. object : array_like
  524. An array, any object exposing the array interface, an
  525. object whose __array__ method returns an array, or any
  526. (nested) sequence.
  527. dtype : data-type, optional
  528. The desired data-type for the array. If not given, then
  529. the type will be determined as the minimum type required
  530. to hold the objects in the sequence. This argument can only
  531. be used to 'upcast' the array. For downcasting, use the
  532. .astype(t) method.
  533. copy : bool, optional
  534. If true (default), then the object is copied. Otherwise, a copy
  535. will only be made if __array__ returns a copy, if obj is a
  536. nested sequence, or if a copy is needed to satisfy any of the other
  537. requirements (`dtype`, `order`, etc.).
  538. order : {'C', 'F', 'A'}, optional
  539. Specify the order of the array. If order is 'C', then the array
  540. will be in C-contiguous order (last-index varies the fastest).
  541. If order is 'F', then the returned array will be in
  542. Fortran-contiguous order (first-index varies the fastest).
  543. If order is 'A' (default), then the returned array may be
  544. in any order (either C-, Fortran-contiguous, or even discontiguous),
  545. unless a copy is required, in which case it will be C-contiguous.
  546. subok : bool, optional
  547. If True, then sub-classes will be passed-through, otherwise
  548. the returned array will be forced to be a base-class array (default).
  549. ndmin : int, optional
  550. Specifies the minimum number of dimensions that the resulting
  551. array should have. Ones will be pre-pended to the shape as
  552. needed to meet this requirement.
  553. Returns
  554. -------
  555. out : ndarray
  556. An array object satisfying the specified requirements.
  557. See Also
  558. --------
  559. empty, empty_like, zeros, zeros_like, ones, ones_like, fill
  560. Examples
  561. --------
  562. >>> np.array([1, 2, 3])
  563. array([1, 2, 3])
  564. Upcasting:
  565. >>> np.array([1, 2, 3.0])
  566. array([ 1., 2., 3.])
  567. More than one dimension:
  568. >>> np.array([[1, 2], [3, 4]])
  569. array([[1, 2],
  570. [3, 4]])
  571. Minimum dimensions 2:
  572. >>> np.array([1, 2, 3], ndmin=2)
  573. array([[1, 2, 3]])
  574. Type provided:
  575. >>> np.array([1, 2, 3], dtype=complex)
  576. array([ 1.+0.j, 2.+0.j, 3.+0.j])
  577. Data-type consisting of more than one element:
  578. >>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')])
  579. >>> x['a']
  580. array([1, 3])
  581. Creating an array from sub-classes:
  582. >>> np.array(np.mat('1 2; 3 4'))
  583. array([[1, 2],
  584. [3, 4]])
  585. >>> np.array(np.mat('1 2; 3 4'), subok=True)
  586. matrix([[1, 2],
  587. [3, 4]])
  588. """)
  589. add_newdoc('numpy.core.multiarray', 'empty',
  590. """
  591. empty(shape, dtype=float, order='C')
  592. Return a new array of given shape and type, without initializing entries.
  593. Parameters
  594. ----------
  595. shape : int or tuple of int
  596. Shape of the empty array
  597. dtype : data-type, optional
  598. Desired output data-type.
  599. order : {'C', 'F'}, optional
  600. Whether to store multi-dimensional data in row-major
  601. (C-style) or column-major (Fortran-style) order in
  602. memory.
  603. Returns
  604. -------
  605. out : ndarray
  606. Array of uninitialized (arbitrary) data of the given shape, dtype, and
  607. order. Object arrays will be initialized to None.
  608. See Also
  609. --------
  610. empty_like, zeros, ones
  611. Notes
  612. -----
  613. `empty`, unlike `zeros`, does not set the array values to zero,
  614. and may therefore be marginally faster. On the other hand, it requires
  615. the user to manually set all the values in the array, and should be
  616. used with caution.
  617. Examples
  618. --------
  619. >>> np.empty([2, 2])
  620. array([[ -9.74499359e+001, 6.69583040e-309],
  621. [ 2.13182611e-314, 3.06959433e-309]]) #random
  622. >>> np.empty([2, 2], dtype=int)
  623. array([[-1073741821, -1067949133],
  624. [ 496041986, 19249760]]) #random
  625. """)
  626. add_newdoc('numpy.core.multiarray', 'empty_like',
  627. """
  628. empty_like(a, dtype=None, order='K', subok=True)
  629. Return a new array with the same shape and type as a given array.
  630. Parameters
  631. ----------
  632. a : array_like
  633. The shape and data-type of `a` define these same attributes of the
  634. returned array.
  635. dtype : data-type, optional
  636. Overrides the data type of the result.
  637. .. versionadded:: 1.6.0
  638. order : {'C', 'F', 'A', or 'K'}, optional
  639. Overrides the memory layout of the result. 'C' means C-order,
  640. 'F' means F-order, 'A' means 'F' if ``a`` is Fortran contiguous,
  641. 'C' otherwise. 'K' means match the layout of ``a`` as closely
  642. as possible.
  643. .. versionadded:: 1.6.0
  644. subok : bool, optional.
  645. If True, then the newly created array will use the sub-class
  646. type of 'a', otherwise it will be a base-class array. Defaults
  647. to True.
  648. Returns
  649. -------
  650. out : ndarray
  651. Array of uninitialized (arbitrary) data with the same
  652. shape and type as `a`.
  653. See Also
  654. --------
  655. ones_like : Return an array of ones with shape and type of input.
  656. zeros_like : Return an array of zeros with shape and type of input.
  657. empty : Return a new uninitialized array.
  658. ones : Return a new array setting values to one.
  659. zeros : Return a new array setting values to zero.
  660. Notes
  661. -----
  662. This function does *not* initialize the returned array; to do that use
  663. `zeros_like` or `ones_like` instead. It may be marginally faster than
  664. the functions that do set the array values.
  665. Examples
  666. --------
  667. >>> a = ([1,2,3], [4,5,6]) # a is array-like
  668. >>> np.empty_like(a)
  669. array([[-1073741821, -1073741821, 3], #random
  670. [ 0, 0, -1073741821]])
  671. >>> a = np.array([[1., 2., 3.],[4.,5.,6.]])
  672. >>> np.empty_like(a)
  673. array([[ -2.00000715e+000, 1.48219694e-323, -2.00000572e+000],#random
  674. [ 4.38791518e-305, -2.00000715e+000, 4.17269252e-309]])
  675. """)
  676. add_newdoc('numpy.core.multiarray', 'scalar',
  677. """
  678. scalar(dtype, obj)
  679. Return a new scalar array of the given type initialized with obj.
  680. This function is meant mainly for pickle support. `dtype` must be a
  681. valid data-type descriptor. If `dtype` corresponds to an object
  682. descriptor, then `obj` can be any object, otherwise `obj` must be a
  683. string. If `obj` is not given, it will be interpreted as None for object
  684. type and as zeros for all other types.
  685. """)
  686. add_newdoc('numpy.core.multiarray', 'zeros',
  687. """
  688. zeros(shape, dtype=float, order='C')
  689. Return a new array of given shape and type, filled with zeros.
  690. Parameters
  691. ----------
  692. shape : int or sequence of ints
  693. Shape of the new array, e.g., ``(2, 3)`` or ``2``.
  694. dtype : data-type, optional
  695. The desired data-type for the array, e.g., `numpy.int8`. Default is
  696. `numpy.float64`.
  697. order : {'C', 'F'}, optional
  698. Whether to store multidimensional data in C- or Fortran-contiguous
  699. (row- or column-wise) order in memory.
  700. Returns
  701. -------
  702. out : ndarray
  703. Array of zeros with the given shape, dtype, and order.
  704. See Also
  705. --------
  706. zeros_like : Return an array of zeros with shape and type of input.
  707. ones_like : Return an array of ones with shape and type of input.
  708. empty_like : Return an empty array with shape and type of input.
  709. ones : Return a new array setting values to one.
  710. empty : Return a new uninitialized array.
  711. Examples
  712. --------
  713. >>> np.zeros(5)
  714. array([ 0., 0., 0., 0., 0.])
  715. >>> np.zeros((5,), dtype=np.int)
  716. array([0, 0, 0, 0, 0])
  717. >>> np.zeros((2, 1))
  718. array([[ 0.],
  719. [ 0.]])
  720. >>> s = (2,2)
  721. >>> np.zeros(s)
  722. array([[ 0., 0.],
  723. [ 0., 0.]])
  724. >>> np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype
  725. array([(0, 0), (0, 0)],
  726. dtype=[('x', '<i4'), ('y', '<i4')])
  727. """)
  728. add_newdoc('numpy.core.multiarray', 'count_nonzero',
  729. """
  730. count_nonzero(a)
  731. Counts the number of non-zero values in the array ``a``.
  732. Parameters
  733. ----------
  734. a : array_like
  735. The array for which to count non-zeros.
  736. Returns
  737. -------
  738. count : int or array of int
  739. Number of non-zero values in the array.
  740. See Also
  741. --------
  742. nonzero : Return the coordinates of all the non-zero values.
  743. Examples
  744. --------
  745. >>> np.count_nonzero(np.eye(4))
  746. 4
  747. >>> np.count_nonzero([[0,1,7,0,0],[3,0,0,2,19]])
  748. 5
  749. """)
  750. add_newdoc('numpy.core.multiarray', 'set_typeDict',
  751. """set_typeDict(dict)
  752. Set the internal dictionary that can look up an array type using a
  753. registered code.
  754. """)
  755. add_newdoc('numpy.core.multiarray', 'fromstring',
  756. """
  757. fromstring(string, dtype=float, count=-1, sep='')
  758. A new 1-D array initialized from raw binary or text data in a string.
  759. Parameters
  760. ----------
  761. string : str
  762. A string containing the data.
  763. dtype : data-type, optional
  764. The data type of the array; default: float. For binary input data,
  765. the data must be in exactly this format.
  766. count : int, optional
  767. Read this number of `dtype` elements from the data. If this is
  768. negative (the default), the count will be determined from the
  769. length of the data.
  770. sep : str, optional
  771. If not provided or, equivalently, the empty string, the data will
  772. be interpreted as binary data; otherwise, as ASCII text with
  773. decimal numbers. Also in this latter case, this argument is
  774. interpreted as the string separating numbers in the data; extra
  775. whitespace between elements is also ignored.
  776. Returns
  777. -------
  778. arr : ndarray
  779. The constructed array.
  780. Raises
  781. ------
  782. ValueError
  783. If the string is not the correct size to satisfy the requested
  784. `dtype` and `count`.
  785. See Also
  786. --------
  787. frombuffer, fromfile, fromiter
  788. Examples
  789. --------
  790. >>> np.fromstring('\\x01\\x02', dtype=np.uint8)
  791. array([1, 2], dtype=uint8)
  792. >>> np.fromstring('1 2', dtype=int, sep=' ')
  793. array([1, 2])
  794. >>> np.fromstring('1, 2', dtype=int, sep=',')
  795. array([1, 2])
  796. >>> np.fromstring('\\x01\\x02\\x03\\x04\\x05', dtype=np.uint8, count=3)
  797. array([1, 2, 3], dtype=uint8)
  798. """)
  799. add_newdoc('numpy.core.multiarray', 'fromiter',
  800. """
  801. fromiter(iterable, dtype, count=-1)
  802. Create a new 1-dimensional array from an iterable object.
  803. Parameters
  804. ----------
  805. iterable : iterable object
  806. An iterable object providing data for the array.
  807. dtype : data-type
  808. The data-type of the returned array.
  809. count : int, optional
  810. The number of items to read from *iterable*. The default is -1,
  811. which means all data is read.
  812. Returns
  813. -------
  814. out : ndarray
  815. The output array.
  816. Notes
  817. -----
  818. Specify `count` to improve performance. It allows ``fromiter`` to
  819. pre-allocate the output array, instead of resizing it on demand.
  820. Examples
  821. --------
  822. >>> iterable = (x*x for x in range(5))
  823. >>> np.fromiter(iterable, np.float)
  824. array([ 0., 1., 4., 9., 16.])
  825. """)
  826. add_newdoc('numpy.core.multiarray', 'fromfile',
  827. """
  828. fromfile(file, dtype=float, count=-1, sep='')
  829. Construct an array from data in a text or binary file.
  830. A highly efficient way of reading binary data with a known data-type,
  831. as well as parsing simply formatted text files. Data written using the
  832. `tofile` method can be read using this function.
  833. Parameters
  834. ----------
  835. file : file or str
  836. Open file object or filename.
  837. dtype : data-type
  838. Data type of the returned array.
  839. For binary files, it is used to determine the size and byte-order
  840. of the items in the file.
  841. count : int
  842. Number of items to read. ``-1`` means all items (i.e., the complete
  843. file).
  844. sep : str
  845. Separator between items if file is a text file.
  846. Empty ("") separator means the file should be treated as binary.
  847. Spaces (" ") in the separator match zero or more whitespace characters.
  848. A separator consisting only of spaces must match at least one
  849. whitespace.
  850. See also
  851. --------
  852. load, save
  853. ndarray.tofile
  854. loadtxt : More flexible way of loading data from a text file.
  855. Notes
  856. -----
  857. Do not rely on the combination of `tofile` and `fromfile` for
  858. data storage, as the binary files generated are are not platform
  859. independent. In particular, no byte-order or data-type information is
  860. saved. Data can be stored in the platform independent ``.npy`` format
  861. using `save` and `load` instead.
  862. Examples
  863. --------
  864. Construct an ndarray:
  865. >>> dt = np.dtype([('time', [('min', int), ('sec', int)]),
  866. ... ('temp', float)])
  867. >>> x = np.zeros((1,), dtype=dt)
  868. >>> x['time']['min'] = 10; x['temp'] = 98.25
  869. >>> x
  870. array([((10, 0), 98.25)],
  871. dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')])
  872. Save the raw data to disk:
  873. >>> import os
  874. >>> fname = os.tmpnam()
  875. >>> x.tofile(fname)
  876. Read the raw data from disk:
  877. >>> np.fromfile(fname, dtype=dt)
  878. array([((10, 0), 98.25)],
  879. dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')])
  880. The recommended way to store and load data:
  881. >>> np.save(fname, x)
  882. >>> np.load(fname + '.npy')
  883. array([((10, 0), 98.25)],
  884. dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')])
  885. """)
  886. add_newdoc('numpy.core.multiarray', 'frombuffer',
  887. """
  888. frombuffer(buffer, dtype=float, count=-1, offset=0)
  889. Interpret a buffer as a 1-dimensional array.
  890. Parameters
  891. ----------
  892. buffer : buffer_like
  893. An object that exposes the buffer interface.
  894. dtype : data-type, optional
  895. Data-type of the returned array; default: float.
  896. count : int, optional
  897. Number of items to read. ``-1`` means all data in the buffer.
  898. offset : int, optional
  899. Start reading the buffer from this offset; default: 0.
  900. Notes
  901. -----
  902. If the buffer has data that is not in machine byte-order, this should
  903. be specified as part of the data-type, e.g.::
  904. >>> dt = np.dtype(int)
  905. >>> dt = dt.newbyteorder('>')
  906. >>> np.frombuffer(buf, dtype=dt)
  907. The data of the resulting array will not be byteswapped, but will be
  908. interpreted correctly.
  909. Examples
  910. --------
  911. >>> s = 'hello world'
  912. >>> np.frombuffer(s, dtype='S1', count=5, offset=6)
  913. array(['w', 'o', 'r', 'l', 'd'],
  914. dtype='|S1')
  915. """)
  916. add_newdoc('numpy.core.multiarray', 'concatenate',
  917. """
  918. concatenate((a1, a2, ...), axis=0)
  919. Join a sequence of arrays along an existing axis.
  920. Parameters
  921. ----------
  922. a1, a2, ... : sequence of array_like
  923. The arrays must have the same shape, except in the dimension
  924. corresponding to `axis` (the first, by default).
  925. axis : int, optional
  926. The axis along which the arrays will be joined. Default is 0.
  927. Returns
  928. -------
  929. res : ndarray
  930. The concatenated array.
  931. See Also
  932. --------
  933. ma.concatenate : Concatenate function that preserves input masks.
  934. array_split : Split an array into multiple sub-arrays of equal or
  935. near-equal size.
  936. split : Split array into a list of multiple sub-arrays of equal size.
  937. hsplit : Split array into multiple sub-arrays horizontally (column wise)
  938. vsplit : Split array into multiple sub-arrays vertically (row wise)
  939. dsplit : Split array into multiple sub-arrays along the 3rd axis (depth).
  940. stack : Stack a sequence of arrays along a new axis.
  941. hstack : Stack arrays in sequence horizontally (column wise)
  942. vstack : Stack arrays in sequence vertically (row wise)
  943. dstack : Stack arrays in sequence depth wise (along third dimension)
  944. Notes
  945. -----
  946. When one or more of the arrays to be concatenated is a MaskedArray,
  947. this function will return a MaskedArray object instead of an ndarray,
  948. but the input masks are *not* preserved. In cases where a MaskedArray
  949. is expected as input, use the ma.concatenate function from the masked
  950. array module instead.
  951. Examples
  952. --------
  953. >>> a = np.array([[1, 2], [3, 4]])
  954. >>> b = np.array([[5, 6]])
  955. >>> np.concatenate((a, b), axis=0)
  956. array([[1, 2],
  957. [3, 4],
  958. [5, 6]])
  959. >>> np.concatenate((a, b.T), axis=1)
  960. array([[1, 2, 5],
  961. [3, 4, 6]])
  962. This function will not preserve masking of MaskedArray inputs.
  963. >>> a = np.ma.arange(3)
  964. >>> a[1] = np.ma.masked
  965. >>> b = np.arange(2, 5)
  966. >>> a
  967. masked_array(data = [0 -- 2],
  968. mask = [False True False],
  969. fill_value = 999999)
  970. >>> b
  971. array([2, 3, 4])
  972. >>> np.concatenate([a, b])
  973. masked_array(data = [0 1 2 2 3 4],
  974. mask = False,
  975. fill_value = 999999)
  976. >>> np.ma.concatenate([a, b])
  977. masked_array(data = [0 -- 2 2 3 4],
  978. mask = [False True False False False False],
  979. fill_value = 999999)
  980. """)
  981. add_newdoc('numpy.core', 'inner',
  982. """
  983. inner(a, b)
  984. Inner product of two arrays.
  985. Ordinary inner product of vectors for 1-D arrays (without complex
  986. conjugation), in higher dimensions a sum product over the last axes.
  987. Parameters
  988. ----------
  989. a, b : array_like
  990. If `a` and `b` are nonscalar, their last dimensions must match.
  991. Returns
  992. -------
  993. out : ndarray
  994. `out.shape = a.shape[:-1] + b.shape[:-1]`
  995. Raises
  996. ------
  997. ValueError
  998. If the last dimension of `a` and `b` has different size.
  999. See Also
  1000. --------
  1001. tensordot : Sum products over arbitrary axes.
  1002. dot : Generalised matrix product, using second last dimension of `b`.
  1003. einsum : Einstein summation convention.
  1004. Notes
  1005. -----
  1006. For vectors (1-D arrays) it computes the ordinary inner-product::
  1007. np.inner(a, b) = sum(a[:]*b[:])
  1008. More generally, if `ndim(a) = r > 0` and `ndim(b) = s > 0`::
  1009. np.inner(a, b) = np.tensordot(a, b, axes=(-1,-1))
  1010. or explicitly::
  1011. np.inner(a, b)[i0,...,ir-1,j0,...,js-1]
  1012. = sum(a[i0,...,ir-1,:]*b[j0,...,js-1,:])
  1013. In addition `a` or `b` may be scalars, in which case::
  1014. np.inner(a,b) = a*b
  1015. Examples
  1016. --------
  1017. Ordinary inner product for vectors:
  1018. >>> a = np.array([1,2,3])
  1019. >>> b = np.array([0,1,0])
  1020. >>> np.inner(a, b)
  1021. 2
  1022. A multidimensional example:
  1023. >>> a = np.arange(24).reshape((2,3,4))
  1024. >>> b = np.arange(4)
  1025. >>> np.inner(a, b)
  1026. array([[ 14, 38, 62],
  1027. [ 86, 110, 134]])
  1028. An example where `b` is a scalar:
  1029. >>> np.inner(np.eye(2), 7)
  1030. array([[ 7., 0.],
  1031. [ 0., 7.]])
  1032. """)
  1033. add_newdoc('numpy.core', 'fastCopyAndTranspose',
  1034. """_fastCopyAndTranspose(a)""")
  1035. add_newdoc('numpy.core.multiarray', 'correlate',
  1036. """cross_correlate(a,v, mode=0)""")
  1037. add_newdoc('numpy.core.multiarray', 'arange',
  1038. """
  1039. arange([start,] stop[, step,], dtype=None)
  1040. Return evenly spaced values within a given interval.
  1041. Values are generated within the half-open interval ``[start, stop)``
  1042. (in other words, the interval including `start` but excluding `stop`).
  1043. For integer arguments the function is equivalent to the Python built-in
  1044. `range <http://docs.python.org/lib/built-in-funcs.html>`_ function,
  1045. but returns an ndarray rather than a list.
  1046. When using a non-integer step, such as 0.1, the results will often not
  1047. be consistent. It is better to use ``linspace`` for these cases.
  1048. Parameters
  1049. ----------
  1050. start : number, optional
  1051. Start of interval. The interval includes this value. The default
  1052. start value is 0.
  1053. stop : number
  1054. End of interval. The interval does not include this value, except
  1055. in some cases where `step` is not an integer and floating point
  1056. round-off affects the length of `out`.
  1057. step : number, optional
  1058. Spacing between values. For any output `out`, this is the distance
  1059. between two adjacent values, ``out[i+1] - out[i]``. The default
  1060. step size is 1. If `step` is specified, `start` must also be given.
  1061. dtype : dtype
  1062. The type of the output array. If `dtype` is not given, infer the data
  1063. type from the other input arguments.
  1064. Returns
  1065. -------
  1066. arange : ndarray
  1067. Array of evenly spaced values.
  1068. For floating point arguments, the length of the result is
  1069. ``ceil((stop - start)/step)``. Because of floating point overflow,
  1070. this rule may result in the last element of `out` being greater
  1071. than `stop`.
  1072. See Also
  1073. --------
  1074. linspace : Evenly spaced numbers with careful handling of endpoints.
  1075. ogrid: Arrays of evenly spaced numbers in N-dimensions.
  1076. mgrid: Grid-shaped arrays of evenly spaced numbers in N-dimensions.
  1077. Examples
  1078. --------
  1079. >>> np.arange(3)
  1080. array([0, 1, 2])
  1081. >>> np.arange(3.0)
  1082. array([ 0., 1., 2.])
  1083. >>> np.arange(3,7)
  1084. array([3, 4, 5, 6])
  1085. >>> np.arange(3,7,2)
  1086. array([3, 5])
  1087. """)
  1088. add_newdoc('numpy.core.multiarray', '_get_ndarray_c_version',
  1089. """_get_ndarray_c_version()
  1090. Return the compile time NDARRAY_VERSION number.
  1091. """)
  1092. add_newdoc('numpy.core.multiarray', '_reconstruct',
  1093. """_reconstruct(subtype, shape, dtype)
  1094. Construct an empty array. Used by Pickles.
  1095. """)
  1096. add_newdoc('numpy.core.multiarray', 'set_string_function',
  1097. """
  1098. set_string_function(f, repr=1)
  1099. Internal method to set a function to be used when pretty printing arrays.
  1100. """)
  1101. add_newdoc('numpy.core.multiarray', 'set_numeric_ops',
  1102. """
  1103. set_numeric_ops(op1=func1, op2=func2, ...)
  1104. Set numerical operators for array objects.
  1105. Parameters
  1106. ----------
  1107. op1, op2, ... : callable
  1108. Each ``op = func`` pair describes an operator to be replaced.
  1109. For example, ``add = lambda x, y: np.add(x, y) % 5`` would replace
  1110. addition by modulus 5 addition.
  1111. Returns
  1112. -------
  1113. saved_ops : list of callables
  1114. A list of all operators, stored before making replacements.
  1115. Notes
  1116. -----
  1117. .. WARNING::
  1118. Use with care! Incorrect usage may lead to memory errors.
  1119. A function replacing an operator cannot make use of that operator.
  1120. For example, when replacing add, you may not use ``+``. Instead,
  1121. directly call ufuncs.
  1122. Examples
  1123. --------
  1124. >>> def add_mod5(x, y):
  1125. ... return np.add(x, y) % 5
  1126. ...
  1127. >>> old_funcs = np.set_numeric_ops(add=add_mod5)
  1128. >>> x = np.arange(12).reshape((3, 4))
  1129. >>> x + x
  1130. array([[0, 2, 4, 1],
  1131. [3, 0, 2, 4],
  1132. [1, 3, 0, 2]])
  1133. >>> ignore = np.set_numeric_ops(**old_funcs) # restore operators
  1134. """)
  1135. add_newdoc('numpy.core.multiarray', 'where',
  1136. """
  1137. where(condition, [x, y])
  1138. Return elements, either from `x` or `y`, depending on `condition`.
  1139. If only `condition` is given, return ``condition.nonzero()``.
  1140. Parameters
  1141. ----------
  1142. condition : array_like, bool
  1143. When True, yield `x`, otherwise yield `y`.
  1144. x, y : array_like, optional
  1145. Values from which to choose. `x` and `y` need to have the same
  1146. shape as `condition`.
  1147. Returns
  1148. -------
  1149. out : ndarray or tuple of ndarrays
  1150. If both `x` and `y` are specified, the output array contains
  1151. elements of `x` where `condition` is True, and elements from
  1152. `y` elsewhere.
  1153. If only `condition` is given, return the tuple
  1154. ``condition.nonzero()``, the indices where `condition` is True.
  1155. See Also
  1156. --------
  1157. nonzero, choose
  1158. Notes
  1159. -----
  1160. If `x` and `y` are given and input arrays are 1-D, `where` is
  1161. equivalent to::
  1162. [xv if c else yv for (c,xv,yv) in zip(condition,x,y)]
  1163. Examples
  1164. --------
  1165. >>> np.where([[True, False], [True, True]],
  1166. ... [[1, 2], [3, 4]],
  1167. ... [[9, 8], [7, 6]])
  1168. array([[1, 8],
  1169. [3, 4]])
  1170. >>> np.where([[0, 1], [1, 0]])
  1171. (array([0, 1]), array([1, 0]))
  1172. >>> x = np.arange(9.).reshape(3, 3)
  1173. >>> np.where( x > 5 )
  1174. (array([2, 2, 2]), array([0, 1, 2]))
  1175. >>> x[np.where( x > 3.0 )] # Note: result is 1D.
  1176. array([ 4., 5., 6., 7., 8.])
  1177. >>> np.where(x < 5, x, -1) # Note: broadcasting.
  1178. array([[ 0., 1., 2.],
  1179. [ 3., 4., -1.],
  1180. [-1., -1., -1.]])
  1181. Find the indices of elements of `x` that are in `goodvalues`.
  1182. >>> goodvalues = [3, 4, 7]
  1183. >>> ix = np.in1d(x.ravel(), goodvalues).reshape(x.shape)
  1184. >>> ix
  1185. array([[False, False, False],
  1186. [ True, True, False],
  1187. [False, True, False]], dtype=bool)
  1188. >>> np.where(ix)
  1189. (array([1, 1, 2]), array([0, 1, 1]))
  1190. """)
  1191. add_newdoc('numpy.core.multiarray', 'lexsort',
  1192. """
  1193. lexsort(keys, axis=-1)
  1194. Perform an indirect sort using a sequence of keys.
  1195. Given multiple sorting keys, which can be interpreted as columns in a
  1196. spreadsheet, lexsort returns an array of integer indices that describes
  1197. the sort order by multiple columns. The last key in the sequence is used
  1198. for the primary sort order, the second-to-last key for the secondary sort
  1199. order, and so on. The keys argument must be a sequence of objects that
  1200. can be converted to arrays of the same shape. If a 2D array is provided
  1201. for the keys argument, it's rows are interpreted as the sorting keys and
  1202. sorting is according to the last row, second last row etc.
  1203. Parameters
  1204. ----------
  1205. keys : (k, N) array or tuple containing k (N,)-shaped sequences
  1206. The `k` different "columns" to be sorted. The last column (or row if
  1207. `keys` is a 2D array) is the primary sort key.
  1208. axis : int, optional
  1209. Axis to be indirectly sorted. By default, sort over the last axis.
  1210. Returns
  1211. -------
  1212. indices : (N,) ndarray of ints
  1213. Array of indices that sort the keys along the specified axis.
  1214. See Also
  1215. --------
  1216. argsort : Indirect sort.
  1217. ndarray.sort : In-place sort.
  1218. sort : Return a sorted copy of an array.
  1219. Examples
  1220. --------
  1221. Sort names: first by surname, then by name.
  1222. >>> surnames = ('Hertz', 'Galilei', 'Hertz')
  1223. >>> first_names = ('Heinrich', 'Galileo', 'Gustav')
  1224. >>> ind = np.lexsort((first_names, surnames))
  1225. >>> ind
  1226. array([1, 2, 0])
  1227. >>> [surnames[i] + ", " + first_names[i] for i in ind]
  1228. ['Galilei, Galileo', 'Hertz, Gustav', 'Hertz, Heinrich']
  1229. Sort two columns of numbers:
  1230. >>> a = [1,5,1,4,3,4,4] # First column
  1231. >>> b = [9,4,0,4,0,2,1] # Second column
  1232. >>> ind = np.lexsort((b,a)) # Sort by a, then by b
  1233. >>> print(ind)
  1234. [2 0 4 6 5 3 1]
  1235. >>> [(a[i],b[i]) for i in ind]
  1236. [(1, 0), (1, 9), (3, 0), (4, 1), (4, 2), (4, 4), (5, 4)]
  1237. Note that sorting is first according to the elements of ``a``.
  1238. Secondary sorting is according to the elements of ``b``.
  1239. A normal ``argsort`` would have yielded:
  1240. >>> [(a[i],b[i]) for i in np.argsort(a)]
  1241. [(1, 9), (1, 0), (3, 0), (4, 4), (4, 2), (4, 1), (5, 4)]
  1242. Structured arrays are sorted lexically by ``argsort``:
  1243. >>> x = np.array([(1,9), (5,4), (1,0), (4,4), (3,0), (4,2), (4,1)],
  1244. ... dtype=np.dtype([('x', int), ('y', int)]))
  1245. >>> np.argsort(x) # or np.argsort(x, order=('x', 'y'))
  1246. array([2, 0, 4, 6, 5, 3, 1])
  1247. """)
  1248. add_newdoc('numpy.core.multiarray', 'can_cast',
  1249. """
  1250. can_cast(from, totype, casting = 'safe')
  1251. Returns True if cast between data types can occur according to the
  1252. casting rule. If from is a scalar or array scalar, also returns
  1253. True if the scalar value can be cast without overflow or truncation
  1254. to an integer.
  1255. Parameters
  1256. ----------
  1257. from : dtype, dtype specifier, scalar, or array
  1258. Data type, scalar, or array to cast from.
  1259. totype : dtype or dtype specifier
  1260. Data type to cast to.
  1261. casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
  1262. Controls what kind of data casting may occur.
  1263. * 'no' means the data types should not be cast at all.
  1264. * 'equiv' means only byte-order changes are allowed.
  1265. * 'safe' means only casts which can preserve values are allowed.
  1266. * 'same_kind' means only safe casts or casts within a kind,
  1267. like float64 to float32, are allowed.
  1268. * 'unsafe' means any data conversions may be done.
  1269. Returns
  1270. -------
  1271. out : bool
  1272. True if cast can occur according to the casting rule.
  1273. Notes
  1274. -----
  1275. Starting in NumPy 1.9, can_cast function now returns False in 'safe'
  1276. casting mode for integer/float dtype and string dtype if the string dtype
  1277. length is not long enough to store the max integer/float value converted
  1278. to a string. Previously can_cast in 'safe' mode returned True for
  1279. integer/float dtype and a string dtype of any length.
  1280. See also
  1281. --------
  1282. dtype, result_type
  1283. Examples
  1284. --------
  1285. Basic examples
  1286. >>> np.can_cast(np.int32, np.int64)
  1287. True
  1288. >>> np.can_cast(np.float64, np.complex)
  1289. True
  1290. >>> np.can_cast(np.complex, np.float)
  1291. False
  1292. >>> np.can_cast('i8', 'f8')
  1293. True
  1294. >>> np.can_cast('i8', 'f4')
  1295. False
  1296. >>> np.can_cast('i4', 'S4')
  1297. False
  1298. Casting scalars
  1299. >>> np.can_cast(100, 'i1')
  1300. True
  1301. >>> np.can_cast(150, 'i1')
  1302. False
  1303. >>> np.can_cast(150, 'u1')
  1304. True
  1305. >>> np.can_cast(3.5e100, np.float32)
  1306. False
  1307. >>> np.can_cast(1000.0, np.float32)
  1308. True
  1309. Array scalar checks the value, array does not
  1310. >>> np.can_cast(np.array(1000.0), np.float32)
  1311. True
  1312. >>> np.can_cast(np.array([1000.0]), np.float32)
  1313. False
  1314. Using the casting rules
  1315. >>> np.can_cast('i8', 'i8', 'no')
  1316. True
  1317. >>> np.can_cast('<i8', '>i8', 'no')
  1318. False
  1319. >>> np.can_cast('<i8', '>i8', 'equiv')
  1320. True
  1321. >>> np.can_cast('<i4', '>i8', 'equiv')
  1322. False
  1323. >>> np.can_cast('<i4', '>i8', 'safe')
  1324. True
  1325. >>> np.can_cast('<i8', '>i4', 'safe')
  1326. False
  1327. >>> np.can_cast('<i8', '>i4', 'same_kind')
  1328. True
  1329. >>> np.can_cast('<i8', '>u4', 'same_kind')
  1330. False
  1331. >>> np.can_cast('<i8', '>u4', 'unsafe')
  1332. True
  1333. """)
  1334. add_newdoc('numpy.core.multiarray', 'promote_types',
  1335. """
  1336. promote_types(type1, type2)
  1337. Returns the data type with the smallest size and smallest scalar
  1338. kind to which both ``type1`` and ``type2`` may be safely cast.
  1339. The returned data type is always in native byte order.
  1340. This function is symmetric and associative.
  1341. Parameters
  1342. ----------
  1343. type1 : dtype or dtype specifier
  1344. First data type.
  1345. type2 : dtype or dtype specifier
  1346. Second data type.
  1347. Returns
  1348. -------
  1349. out : dtype
  1350. The promoted data type.
  1351. Notes
  1352. -----
  1353. .. versionadded:: 1.6.0
  1354. Starting in NumPy 1.9, promote_types function now returns a valid string
  1355. length when given an integer or float dtype as one argument and a string
  1356. dtype as another argument. Previously it always returned the input string
  1357. dtype, even if it wasn't long enough to store the max integer/float value
  1358. converted to a string.
  1359. See Also
  1360. --------
  1361. result_type, dtype, can_cast
  1362. Examples
  1363. --------
  1364. >>> np.promote_types('f4', 'f8')
  1365. dtype('float64')
  1366. >>> np.promote_types('i8', 'f4')
  1367. dtype('float64')
  1368. >>> np.promote_types('>i8', '<c8')
  1369. dtype('complex128')
  1370. >>> np.promote_types('i4', 'S8')
  1371. dtype('S11')
  1372. """)
  1373. add_newdoc('numpy.core.multiarray', 'min_scalar_type',
  1374. """
  1375. min_scalar_type(a)
  1376. For scalar ``a``, returns the data type with the smallest size
  1377. and smallest scalar kind which can hold its value. For non-scalar
  1378. array ``a``, returns the vector's dtype unmodified.
  1379. Floating point values are not demoted to integers,
  1380. and complex values are not demoted to floats.
  1381. Parameters
  1382. ----------
  1383. a : scalar or array_like
  1384. The value whose minimal data type is to be found.
  1385. Returns
  1386. -------
  1387. out : dtype
  1388. The minimal data type.
  1389. Notes
  1390. -----
  1391. .. versionadded:: 1.6.0
  1392. See Also
  1393. --------
  1394. result_type, promote_types, dtype, can_cast
  1395. Examples
  1396. --------
  1397. >>> np.min_scalar_type(10)
  1398. dtype('uint8')
  1399. >>> np.min_scalar_type(-260)
  1400. dtype('int16')
  1401. >>> np.min_scalar_type(3.1)
  1402. dtype('float16')
  1403. >>> np.min_scalar_type(1e50)
  1404. dtype('float64')
  1405. >>> np.min_scalar_type(np.arange(4,dtype='f8'))
  1406. dtype('float64')
  1407. """)
  1408. add_newdoc('numpy.core.multiarray', 'result_type',
  1409. """
  1410. result_type(*arrays_and_dtypes)
  1411. Returns the type that results from applying the NumPy
  1412. type promotion rules to the arguments.
  1413. Type promotion in NumPy works similarly to the rules in languages
  1414. like C++, with some slight differences. When both scalars and
  1415. arrays are used, the array's type takes precedence and the actual value
  1416. of the scalar is taken into account.
  1417. For example, calculating 3*a, where a is an array of 32-bit floats,
  1418. intuitively should result in a 32-bit float output. If the 3 is a
  1419. 32-bit integer, the NumPy rules indicate it can't convert losslessly
  1420. into a 32-bit float, so a 64-bit float should be the result type.
  1421. By examining the value of the constant, '3', we see that it fits in
  1422. an 8-bit integer, which can be cast losslessly into the 32-bit float.
  1423. Parameters
  1424. ----------
  1425. arrays_and_dtypes : list of arrays and dtypes
  1426. The operands of some operation whose result type is needed.
  1427. Returns
  1428. -------
  1429. out : dtype
  1430. The result type.
  1431. See also
  1432. --------
  1433. dtype, promote_types, min_scalar_type, can_cast
  1434. Notes
  1435. -----
  1436. .. versionadded:: 1.6.0
  1437. The specific algorithm used is as follows.
  1438. Categories are determined by first checking which of boolean,
  1439. integer (int/uint), or floating point (float/complex) the maximum
  1440. kind of all the arrays and the scalars are.
  1441. If there are only scalars or the maximum category of the scalars
  1442. is higher than the maximum category of the arrays,
  1443. the data types are combined with :func:`promote_types`
  1444. to produce the return value.
  1445. Otherwise, `min_scalar_type` is called on each array, and
  1446. the resulting data types are all combined with :func:`promote_types`
  1447. to produce the return value.
  1448. The set of int values is not a subset of the uint values for types
  1449. with the same number of bits, something not reflected in
  1450. :func:`min_scalar_type`, but handled as a special case in `result_type`.
  1451. Examples
  1452. --------
  1453. >>> np.result_type(3, np.arange(7, dtype='i1'))
  1454. dtype('int8')
  1455. >>> np.result_type('i4', 'c8')
  1456. dtype('complex128')
  1457. >>> np.result_type(3.0, -2)
  1458. dtype('float64')
  1459. """)
  1460. add_newdoc('numpy.core.multiarray', 'newbuffer',
  1461. """
  1462. newbuffer(size)
  1463. Return a new uninitialized buffer object.
  1464. Parameters
  1465. ----------
  1466. size : int
  1467. Size in bytes of returned buffer object.
  1468. Returns
  1469. -------
  1470. newbuffer : buffer object
  1471. Returned, uninitialized buffer object of `size` bytes.
  1472. """)
  1473. add_newdoc('numpy.core.multiarray', 'getbuffer',
  1474. """
  1475. getbuffer(obj [,offset[, size]])
  1476. Create a buffer object from the given object referencing a slice of
  1477. length size starting at offset.
  1478. Default is the entire buffer. A read-write buffer is attempted followed
  1479. by a read-only buffer.
  1480. Parameters
  1481. ----------
  1482. obj : object
  1483. offset : int, optional
  1484. size : int, optional
  1485. Returns
  1486. -------
  1487. buffer_obj : buffer
  1488. Examples
  1489. --------
  1490. >>> buf = np.getbuffer(np.ones(5), 1, 3)
  1491. >>> len(buf)
  1492. 3
  1493. >>> buf[0]
  1494. '\\x00'
  1495. >>> buf
  1496. <read-write buffer for 0x8af1e70, size 3, offset 1 at 0x8ba4ec0>
  1497. """)
  1498. add_newdoc('numpy.core', 'dot',
  1499. """
  1500. dot(a, b, out=None)
  1501. Dot product of two arrays.
  1502. For 2-D arrays it is equivalent to matrix multiplication, and for 1-D
  1503. arrays to inner product of vectors (without complex conjugation). For
  1504. N dimensions it is a sum product over the last axis of `a` and
  1505. the second-to-last of `b`::
  1506. dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])
  1507. Parameters
  1508. ----------
  1509. a : array_like
  1510. First argument.
  1511. b : array_like
  1512. Second argument.
  1513. out : ndarray, optional
  1514. Output argument. This must have the exact kind that would be returned
  1515. if it was not used. In particular, it must have the right type, must be
  1516. C-contiguous, and its dtype must be the dtype that would be returned
  1517. for `dot(a,b)`. This is a performance feature. Therefore, if these
  1518. conditions are not met, an exception is raised, instead of attempting
  1519. to be flexible.
  1520. Returns
  1521. -------
  1522. output : ndarray
  1523. Returns the dot product of `a` and `b`. If `a` and `b` are both
  1524. scalars or both 1-D arrays then a scalar is returned; otherwise
  1525. an array is returned.
  1526. If `out` is given, then it is returned.
  1527. Raises
  1528. ------
  1529. ValueError
  1530. If the last dimension of `a` is not the same size as
  1531. the second-to-last dimension of `b`.
  1532. See Also
  1533. --------
  1534. vdot : Complex-conjugating dot product.
  1535. tensordot : Sum products over arbitrary axes.
  1536. einsum : Einstein summation convention.
  1537. matmul : '@' operator as method with out parameter.
  1538. Examples
  1539. --------
  1540. >>> np.dot(3, 4)
  1541. 12
  1542. Neither argument is complex-conjugated:
  1543. >>> np.dot([2j, 3j], [2j, 3j])
  1544. (-13+0j)
  1545. For 2-D arrays it is the matrix product:
  1546. >>> a = [[1, 0], [0, 1]]
  1547. >>> b = [[4, 1], [2, 2]]
  1548. >>> np.dot(a, b)
  1549. array([[4, 1],
  1550. [2, 2]])
  1551. >>> a = np.arange(3*4*5*6).reshape((3,4,5,6))
  1552. >>> b = np.arange(3*4*5*6)[::-1].reshape((5,4,6,3))
  1553. >>> np.dot(a, b)[2,3,2,1,2,2]
  1554. 499128
  1555. >>> sum(a[2,3,2,:] * b[1,2,:,2])
  1556. 499128
  1557. """)
  1558. add_newdoc('numpy.core', 'matmul',
  1559. """
  1560. matmul(a, b, out=None)
  1561. Matrix product of two arrays.
  1562. The behavior depends on the arguments in the following way.
  1563. - If both arguments are 2-D they are multiplied like conventional
  1564. matrices.
  1565. - If either argument is N-D, N > 2, it is treated as a stack of
  1566. matrices residing in the last two indexes and broadcast accordingly.
  1567. - If the first argument is 1-D, it is promoted to a matrix by
  1568. prepending a 1 to its dimensions. After matrix multiplication
  1569. the prepended 1 is removed.
  1570. - If the second argument is 1-D, it is promoted to a matrix by
  1571. appending a 1 to its dimensions. After matrix multiplication
  1572. the appended 1 is removed.
  1573. Multiplication by a scalar is not allowed, use ``*`` instead. Note that
  1574. multiplying a stack of matrices with a vector will result in a stack of
  1575. vectors, but matmul will not recognize it as such.
  1576. ``matmul`` differs from ``dot`` in two important ways.
  1577. - Multiplication by scalars is not allowed.
  1578. - Stacks of matrices are broadcast together as if the matrices
  1579. were elements.
  1580. .. warning::
  1581. This function is preliminary and included in Numpy 1.10 for testing
  1582. and documentation. Its semantics will not change, but the number and
  1583. order of the optional arguments will.
  1584. .. versionadded:: 1.10.0
  1585. Parameters
  1586. ----------
  1587. a : array_like
  1588. First argument.
  1589. b : array_like
  1590. Second argument.
  1591. out : ndarray, optional
  1592. Output argument. This must have the exact kind that would be returned
  1593. if it was not used. In particular, it must have the right type, must be
  1594. C-contiguous, and its dtype must be the dtype that would be returned
  1595. for `dot(a,b)`. This is a performance feature. Therefore, if these
  1596. conditions are not met, an exception is raised, instead of attempting
  1597. to be flexible.
  1598. Returns
  1599. -------
  1600. output : ndarray
  1601. Returns the dot product of `a` and `b`. If `a` and `b` are both
  1602. 1-D arrays then a scalar is returned; otherwise an array is
  1603. returned. If `out` is given, then it is returned.
  1604. Raises
  1605. ------
  1606. ValueError
  1607. If the last dimension of `a` is not the same size as
  1608. the second-to-last dimension of `b`.
  1609. If scalar value is passed.
  1610. See Also
  1611. --------
  1612. vdot : Complex-conjugating dot product.
  1613. tensordot : Sum products over arbitrary axes.
  1614. einsum : Einstein summation convention.
  1615. dot : alternative matrix product with different broadcasting rules.
  1616. Notes
  1617. -----
  1618. The matmul function implements the semantics of the `@` operator introduced
  1619. in Python 3.5 following PEP465.
  1620. Examples
  1621. --------
  1622. For 2-D arrays it is the matrix product:
  1623. >>> a = [[1, 0], [0, 1]]
  1624. >>> b = [[4, 1], [2, 2]]
  1625. >>> np.matmul(a, b)
  1626. array([[4, 1],
  1627. [2, 2]])
  1628. For 2-D mixed with 1-D, the result is the usual.
  1629. >>> a = [[1, 0], [0, 1]]
  1630. >>> b = [1, 2]
  1631. >>> np.matmul(a, b)
  1632. array([1, 2])
  1633. >>> np.matmul(b, a)
  1634. array([1, 2])
  1635. Broadcasting is conventional for stacks of arrays
  1636. >>> a = np.arange(2*2*4).reshape((2,2,4))
  1637. >>> b = np.arange(2*2*4).reshape((2,4,2))
  1638. >>> np.matmul(a,b).shape
  1639. (2, 2, 2)
  1640. >>> np.matmul(a,b)[0,1,1]
  1641. 98
  1642. >>> sum(a[0,1,:] * b[0,:,1])
  1643. 98
  1644. Vector, vector returns the scalar inner product, but neither argument
  1645. is complex-conjugated:
  1646. >>> np.matmul([2j, 3j], [2j, 3j])
  1647. (-13+0j)
  1648. Scalar multiplication raises an error.
  1649. >>> np.matmul([1,2], 3)
  1650. Traceback (most recent call last):
  1651. ...
  1652. ValueError: Scalar operands are not allowed, use '*' instead
  1653. """)
  1654. add_newdoc('numpy.core', 'einsum',
  1655. """
  1656. einsum(subscripts, *operands, out=None, dtype=None, order='K', casting='safe')
  1657. Evaluates the Einstein summation convention on the operands.
  1658. Using the Einstein summation convention, many common multi-dimensional
  1659. array operations can be represented in a simple fashion. This function
  1660. provides a way to compute such summations. The best way to understand this
  1661. function is to try the examples below, which show how many common NumPy
  1662. functions can be implemented as calls to `einsum`.
  1663. Parameters
  1664. ----------
  1665. subscripts : str
  1666. Specifies the subscripts for summation.
  1667. operands : list of array_like
  1668. These are the arrays for the operation.
  1669. out : ndarray, optional
  1670. If provided, the calculation is done into this array.
  1671. dtype : data-type, optional
  1672. If provided, forces the calculation to use the data type specified.
  1673. Note that you may have to also give a more liberal `casting`
  1674. parameter to allow the conversions.
  1675. order : {'C', 'F', 'A', 'K'}, optional
  1676. Controls the memory layout of the output. 'C' means it should
  1677. be C contiguous. 'F' means it should be Fortran contiguous,
  1678. 'A' means it should be 'F' if the inputs are all 'F', 'C' otherwise.
  1679. 'K' means it should be as close to the layout as the inputs as
  1680. is possible, including arbitrarily permuted axes.
  1681. Default is 'K'.
  1682. casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
  1683. Controls what kind of data casting may occur. Setting this to
  1684. 'unsafe' is not recommended, as it can adversely affect accumulations.
  1685. * 'no' means the data types should not be cast at all.
  1686. * 'equiv' means only byte-order changes are allowed.
  1687. * 'safe' means only casts which can preserve values are allowed.
  1688. * 'same_kind' means only safe casts or casts within a kind,
  1689. like float64 to float32, are allowed.
  1690. * 'unsafe' means any data conversions may be done.
  1691. Returns
  1692. -------
  1693. output : ndarray
  1694. The calculation based on the Einstein summation convention.
  1695. See Also
  1696. --------
  1697. dot, inner, outer, tensordot
  1698. Notes
  1699. -----
  1700. .. versionadded:: 1.6.0
  1701. The subscripts string is a comma-separated list of subscript labels,
  1702. where each label refers to a dimension of the corresponding operand.
  1703. Repeated subscripts labels in one operand take the diagonal. For example,
  1704. ``np.einsum('ii', a)`` is equivalent to ``np.trace(a)``.
  1705. Whenever a label is repeated, it is summed, so ``np.einsum('i,i', a, b)``
  1706. is equivalent to ``np.inner(a,b)``. If a label appears only once,
  1707. it is not summed, so ``np.einsum('i', a)`` produces a view of ``a``
  1708. with no changes.
  1709. The order of labels in the output is by default alphabetical. This
  1710. means that ``np.einsum('ij', a)`` doesn't affect a 2D array, while
  1711. ``np.einsum('ji', a)`` takes its transpose.
  1712. The output can be controlled by specifying output subscript labels
  1713. as well. This specifies the label order, and allows summing to
  1714. be disallowed or forced when desired. The call ``np.einsum('i->', a)``
  1715. is like ``np.sum(a, axis=-1)``, and ``np.einsum('ii->i', a)``
  1716. is like ``np.diag(a)``. The difference is that `einsum` does not
  1717. allow broadcasting by default.
  1718. To enable and control broadcasting, use an ellipsis. Default
  1719. NumPy-style broadcasting is done by adding an ellipsis
  1720. to the left of each term, like ``np.einsum('...ii->...i', a)``.
  1721. To take the trace along the first and last axes,
  1722. you can do ``np.einsum('i...i', a)``, or to do a matrix-matrix
  1723. product with the left-most indices instead of rightmost, you can do
  1724. ``np.einsum('ij...,jk...->ik...', a, b)``.
  1725. When there is only one operand, no axes are summed, and no output
  1726. parameter is provided, a view into the operand is returned instead
  1727. of a new array. Thus, taking the diagonal as ``np.einsum('ii->i', a)``
  1728. produces a view.
  1729. An alternative way to provide the subscripts and operands is as
  1730. ``einsum(op0, sublist0, op1, sublist1, ..., [sublistout])``. The examples
  1731. below have corresponding `einsum` calls with the two parameter methods.
  1732. .. versionadded:: 1.10.0
  1733. Views returned from einsum are now writeable whenever the input array
  1734. is writeable. For example, ``np.einsum('ijk...->kji...', a)`` will now
  1735. have the same effect as ``np.swapaxes(a, 0, 2)`` and
  1736. ``np.einsum('ii->i', a)`` will return a writeable view of the diagonal
  1737. of a 2D array.
  1738. Examples
  1739. --------
  1740. >>> a = np.arange(25).reshape(5,5)
  1741. >>> b = np.arange(5)
  1742. >>> c = np.arange(6).reshape(2,3)
  1743. >>> np.einsum('ii', a)
  1744. 60
  1745. >>> np.einsum(a, [0,0])
  1746. 60
  1747. >>> np.trace(a)
  1748. 60
  1749. >>> np.einsum('ii->i', a)
  1750. array([ 0, 6, 12, 18, 24])
  1751. >>> np.einsum(a, [0,0], [0])
  1752. array([ 0, 6, 12, 18, 24])
  1753. >>> np.diag(a)
  1754. array([ 0, 6, 12, 18, 24])
  1755. >>> np.einsum('ij,j', a, b)
  1756. array([ 30, 80, 130, 180, 230])
  1757. >>> np.einsum(a, [0,1], b, [1])
  1758. array([ 30, 80, 130, 180, 230])
  1759. >>> np.dot(a, b)
  1760. array([ 30, 80, 130, 180, 230])
  1761. >>> np.einsum('...j,j', a, b)
  1762. array([ 30, 80, 130, 180, 230])
  1763. >>> np.einsum('ji', c)
  1764. array([[0, 3],
  1765. [1, 4],
  1766. [2, 5]])
  1767. >>> np.einsum(c, [1,0])
  1768. array([[0, 3],
  1769. [1, 4],
  1770. [2, 5]])
  1771. >>> c.T
  1772. array([[0, 3],
  1773. [1, 4],
  1774. [2, 5]])
  1775. >>> np.einsum('..., ...', 3, c)
  1776. array([[ 0, 3, 6],
  1777. [ 9, 12, 15]])
  1778. >>> np.einsum(3, [Ellipsis], c, [Ellipsis])
  1779. array([[ 0, 3, 6],
  1780. [ 9, 12, 15]])
  1781. >>> np.multiply(3, c)
  1782. array([[ 0, 3, 6],
  1783. [ 9, 12, 15]])
  1784. >>> np.einsum('i,i', b, b)
  1785. 30
  1786. >>> np.einsum(b, [0], b, [0])
  1787. 30
  1788. >>> np.inner(b,b)
  1789. 30
  1790. >>> np.einsum('i,j', np.arange(2)+1, b)
  1791. array([[0, 1, 2, 3, 4],
  1792. [0, 2, 4, 6, 8]])
  1793. >>> np.einsum(np.arange(2)+1, [0], b, [1])
  1794. array([[0, 1, 2, 3, 4],
  1795. [0, 2, 4, 6, 8]])
  1796. >>> np.outer(np.arange(2)+1, b)
  1797. array([[0, 1, 2, 3, 4],
  1798. [0, 2, 4, 6, 8]])
  1799. >>> np.einsum('i...->...', a)
  1800. array([50, 55, 60, 65, 70])
  1801. >>> np.einsum(a, [0,Ellipsis], [Ellipsis])
  1802. array([50, 55, 60, 65, 70])
  1803. >>> np.sum(a, axis=0)
  1804. array([50, 55, 60, 65, 70])
  1805. >>> a = np.arange(60.).reshape(3,4,5)
  1806. >>> b = np.arange(24.).reshape(4,3,2)
  1807. >>> np.einsum('ijk,jil->kl', a, b)
  1808. array([[ 4400., 4730.],
  1809. [ 4532., 4874.],
  1810. [ 4664., 5018.],
  1811. [ 4796., 5162.],
  1812. [ 4928., 5306.]])
  1813. >>> np.einsum(a, [0,1,2], b, [1,0,3], [2,3])
  1814. array([[ 4400., 4730.],
  1815. [ 4532., 4874.],
  1816. [ 4664., 5018.],
  1817. [ 4796., 5162.],
  1818. [ 4928., 5306.]])
  1819. >>> np.tensordot(a,b, axes=([1,0],[0,1]))
  1820. array([[ 4400., 4730.],
  1821. [ 4532., 4874.],
  1822. [ 4664., 5018.],
  1823. [ 4796., 5162.],
  1824. [ 4928., 5306.]])
  1825. >>> a = np.arange(6).reshape((3,2))
  1826. >>> b = np.arange(12).reshape((4,3))
  1827. >>> np.einsum('ki,jk->ij', a, b)
  1828. array([[10, 28, 46, 64],
  1829. [13, 40, 67, 94]])
  1830. >>> np.einsum('ki,...k->i...', a, b)
  1831. array([[10, 28, 46, 64],
  1832. [13, 40, 67, 94]])
  1833. >>> np.einsum('k...,jk', a, b)
  1834. array([[10, 28, 46, 64],
  1835. [13, 40, 67, 94]])
  1836. >>> # since version 1.10.0
  1837. >>> a = np.zeros((3, 3))
  1838. >>> np.einsum('ii->i', a)[:] = 1
  1839. >>> a
  1840. array([[ 1., 0., 0.],
  1841. [ 0., 1., 0.],
  1842. [ 0., 0., 1.]])
  1843. """)
  1844. add_newdoc('numpy.core', 'vdot',
  1845. """
  1846. vdot(a, b)
  1847. Return the dot product of two vectors.
  1848. The vdot(`a`, `b`) function handles complex numbers differently than
  1849. dot(`a`, `b`). If the first argument is complex the complex conjugate
  1850. of the first argument is used for the calculation of the dot product.
  1851. Note that `vdot` handles multidimensional arrays differently than `dot`:
  1852. it does *not* perform a matrix product, but flattens input arguments
  1853. to 1-D vectors first. Consequently, it should only be used for vectors.
  1854. Parameters
  1855. ----------
  1856. a : array_like
  1857. If `a` is complex the complex conjugate is taken before calculation
  1858. of the dot product.
  1859. b : array_like
  1860. Second argument to the dot product.
  1861. Returns
  1862. -------
  1863. output : ndarray
  1864. Dot product of `a` and `b`. Can be an int, float, or
  1865. complex depending on the types of `a` and `b`.
  1866. See Also
  1867. --------
  1868. dot : Return the dot product without using the complex conjugate of the
  1869. first argument.
  1870. Examples
  1871. --------
  1872. >>> a = np.array([1+2j,3+4j])
  1873. >>> b = np.array([5+6j,7+8j])
  1874. >>> np.vdot(a, b)
  1875. (70-8j)
  1876. >>> np.vdot(b, a)
  1877. (70+8j)
  1878. Note that higher-dimensional arrays are flattened!
  1879. >>> a = np.array([[1, 4], [5, 6]])
  1880. >>> b = np.array([[4, 1], [2, 2]])
  1881. >>> np.vdot(a, b)
  1882. 30
  1883. >>> np.vdot(b, a)
  1884. 30
  1885. >>> 1*4 + 4*1 + 5*2 + 6*2
  1886. 30
  1887. """)
  1888. ##############################################################################
  1889. #
  1890. # Documentation for ndarray attributes and methods
  1891. #
  1892. ##############################################################################
  1893. ##############################################################################
  1894. #
  1895. # ndarray object
  1896. #
  1897. ##############################################################################
  1898. add_newdoc('numpy.core.multiarray', 'ndarray',
  1899. """
  1900. ndarray(shape, dtype=float, buffer=None, offset=0,
  1901. strides=None, order=None)
  1902. An array object represents a multidimensional, homogeneous array
  1903. of fixed-size items. An associated data-type object describes the
  1904. format of each element in the array (its byte-order, how many bytes it
  1905. occupies in memory, whether it is an integer, a floating point number,
  1906. or something else, etc.)
  1907. Arrays should be constructed using `array`, `zeros` or `empty` (refer
  1908. to the See Also section below). The parameters given here refer to
  1909. a low-level method (`ndarray(...)`) for instantiating an array.
  1910. For more information, refer to the `numpy` module and examine the
  1911. the methods and attributes of an array.
  1912. Parameters
  1913. ----------
  1914. (for the __new__ method; see Notes below)
  1915. shape : tuple of ints
  1916. Shape of created array.
  1917. dtype : data-type, optional
  1918. Any object that can be interpreted as a numpy data type.
  1919. buffer : object exposing buffer interface, optional
  1920. Used to fill the array with data.
  1921. offset : int, optional
  1922. Offset of array data in buffer.
  1923. strides : tuple of ints, optional
  1924. Strides of data in memory.
  1925. order : {'C', 'F'}, optional
  1926. Row-major (C-style) or column-major (Fortran-style) order.
  1927. Attributes
  1928. ----------
  1929. T : ndarray
  1930. Transpose of the array.
  1931. data : buffer
  1932. The array's elements, in memory.
  1933. dtype : dtype object
  1934. Describes the format of the elements in the array.
  1935. flags : dict
  1936. Dictionary containing information related to memory use, e.g.,
  1937. 'C_CONTIGUOUS', 'OWNDATA', 'WRITEABLE', etc.
  1938. flat : numpy.flatiter object
  1939. Flattened version of the array as an iterator. The iterator
  1940. allows assignments, e.g., ``x.flat = 3`` (See `ndarray.flat` for
  1941. assignment examples; TODO).
  1942. imag : ndarray
  1943. Imaginary part of the array.
  1944. real : ndarray
  1945. Real part of the array.
  1946. size : int
  1947. Number of elements in the array.
  1948. itemsize : int
  1949. The memory use of each array element in bytes.
  1950. nbytes : int
  1951. The total number of bytes required to store the array data,
  1952. i.e., ``itemsize * size``.
  1953. ndim : int
  1954. The array's number of dimensions.
  1955. shape : tuple of ints
  1956. Shape of the array.
  1957. strides : tuple of ints
  1958. The step-size required to move from one element to the next in
  1959. memory. For example, a contiguous ``(3, 4)`` array of type
  1960. ``int16`` in C-order has strides ``(8, 2)``. This implies that
  1961. to move from element to element in memory requires jumps of 2 bytes.
  1962. To move from row-to-row, one needs to jump 8 bytes at a time
  1963. (``2 * 4``).
  1964. ctypes : ctypes object
  1965. Class containing properties of the array needed for interaction
  1966. with ctypes.
  1967. base : ndarray
  1968. If the array is a view into another array, that array is its `base`
  1969. (unless that array is also a view). The `base` array is where the
  1970. array data is actually stored.
  1971. See Also
  1972. --------
  1973. array : Construct an array.
  1974. zeros : Create an array, each element of which is zero.
  1975. empty : Create an array, but leave its allocated memory unchanged (i.e.,
  1976. it contains "garbage").
  1977. dtype : Create a data-type.
  1978. Notes
  1979. -----
  1980. There are two modes of creating an array using ``__new__``:
  1981. 1. If `buffer` is None, then only `shape`, `dtype`, and `order`
  1982. are used.
  1983. 2. If `buffer` is an object exposing the buffer interface, then
  1984. all keywords are interpreted.
  1985. No ``__init__`` method is needed because the array is fully initialized
  1986. after the ``__new__`` method.
  1987. Examples
  1988. --------
  1989. These examples illustrate the low-level `ndarray` constructor. Refer
  1990. to the `See Also` section above for easier ways of constructing an
  1991. ndarray.
  1992. First mode, `buffer` is None:
  1993. >>> np.ndarray(shape=(2,2), dtype=float, order='F')
  1994. array([[ -1.13698227e+002, 4.25087011e-303],
  1995. [ 2.88528414e-306, 3.27025015e-309]]) #random
  1996. Second mode:
  1997. >>> np.ndarray((2,), buffer=np.array([1,2,3]),
  1998. ... offset=np.int_().itemsize,
  1999. ... dtype=int) # offset = 1*itemsize, i.e. skip first element
  2000. array([2, 3])
  2001. """)
  2002. ##############################################################################
  2003. #
  2004. # ndarray attributes
  2005. #
  2006. ##############################################################################
  2007. add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_interface__',
  2008. """Array protocol: Python side."""))
  2009. add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_finalize__',
  2010. """None."""))
  2011. add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_priority__',
  2012. """Array priority."""))
  2013. add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_struct__',
  2014. """Array protocol: C-struct side."""))
  2015. add_newdoc('numpy.core.multiarray', 'ndarray', ('_as_parameter_',
  2016. """Allow the array to be interpreted as a ctypes object by returning the
  2017. data-memory location as an integer
  2018. """))
  2019. add_newdoc('numpy.core.multiarray', 'ndarray', ('base',
  2020. """
  2021. Base object if memory is from some other object.
  2022. Examples
  2023. --------
  2024. The base of an array that owns its memory is None:
  2025. >>> x = np.array([1,2,3,4])
  2026. >>> x.base is None
  2027. True
  2028. Slicing creates a view, whose memory is shared with x:
  2029. >>> y = x[2:]
  2030. >>> y.base is x
  2031. True
  2032. """))
  2033. add_newdoc('numpy.core.multiarray', 'ndarray', ('ctypes',
  2034. """
  2035. An object to simplify the interaction of the array with the ctypes
  2036. module.
  2037. This attribute creates an object that makes it easier to use arrays
  2038. when calling shared libraries with the ctypes module. The returned
  2039. object has, among others, data, shape, and strides attributes (see
  2040. Notes below) which themselves return ctypes objects that can be used
  2041. as arguments to a shared library.
  2042. Parameters
  2043. ----------
  2044. None
  2045. Returns
  2046. -------
  2047. c : Python object
  2048. Possessing attributes data, shape, strides, etc.
  2049. See Also
  2050. --------
  2051. numpy.ctypeslib
  2052. Notes
  2053. -----
  2054. Below are the public attributes of this object which were documented
  2055. in "Guide to NumPy" (we have omitted undocumented public attributes,
  2056. as well as documented private attributes):
  2057. * data: A pointer to the memory area of the array as a Python integer.
  2058. This memory area may contain data that is not aligned, or not in correct
  2059. byte-order. The memory area may not even be writeable. The array
  2060. flags and data-type of this array should be respected when passing this
  2061. attribute to arbitrary C-code to avoid trouble that can include Python
  2062. crashing. User Beware! The value of this attribute is exactly the same
  2063. as self._array_interface_['data'][0].
  2064. * shape (c_intp*self.ndim): A ctypes array of length self.ndim where
  2065. the basetype is the C-integer corresponding to dtype('p') on this
  2066. platform. This base-type could be c_int, c_long, or c_longlong
  2067. depending on the platform. The c_intp type is defined accordingly in
  2068. numpy.ctypeslib. The ctypes array contains the shape of the underlying
  2069. array.
  2070. * strides (c_intp*self.ndim): A ctypes array of length self.ndim where
  2071. the basetype is the same as for the shape attribute. This ctypes array
  2072. contains the strides information from the underlying array. This strides
  2073. information is important for showing how many bytes must be jumped to
  2074. get to the next element in the array.
  2075. * data_as(obj): Return the data pointer cast to a particular c-types object.
  2076. For example, calling self._as_parameter_ is equivalent to
  2077. self.data_as(ctypes.c_void_p). Perhaps you want to use the data as a
  2078. pointer to a ctypes array of floating-point data:
  2079. self.data_as(ctypes.POINTER(ctypes.c_double)).
  2080. * shape_as(obj): Return the shape tuple as an array of some other c-types
  2081. type. For example: self.shape_as(ctypes.c_short).
  2082. * strides_as(obj): Return the strides tuple as an array of some other
  2083. c-types type. For example: self.strides_as(ctypes.c_longlong).
  2084. Be careful using the ctypes attribute - especially on temporary
  2085. arrays or arrays constructed on the fly. For example, calling
  2086. ``(a+b).ctypes.data_as(ctypes.c_void_p)`` returns a pointer to memory
  2087. that is invalid because the array created as (a+b) is deallocated
  2088. before the next Python statement. You can avoid this problem using
  2089. either ``c=a+b`` or ``ct=(a+b).ctypes``. In the latter case, ct will
  2090. hold a reference to the array until ct is deleted or re-assigned.
  2091. If the ctypes module is not available, then the ctypes attribute
  2092. of array objects still returns something useful, but ctypes objects
  2093. are not returned and errors may be raised instead. In particular,
  2094. the object will still have the as parameter attribute which will
  2095. return an integer equal to the data attribute.
  2096. Examples
  2097. --------
  2098. >>> import ctypes
  2099. >>> x
  2100. array([[0, 1],
  2101. [2, 3]])
  2102. >>> x.ctypes.data
  2103. 30439712
  2104. >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_long))
  2105. <ctypes.LP_c_long object at 0x01F01300>
  2106. >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_long)).contents
  2107. c_long(0)
  2108. >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_longlong)).contents
  2109. c_longlong(4294967296L)
  2110. >>> x.ctypes.shape
  2111. <numpy.core._internal.c_long_Array_2 object at 0x01FFD580>
  2112. >>> x.ctypes.shape_as(ctypes.c_long)
  2113. <numpy.core._internal.c_long_Array_2 object at 0x01FCE620>
  2114. >>> x.ctypes.strides
  2115. <numpy.core._internal.c_long_Array_2 object at 0x01FCE620>
  2116. >>> x.ctypes.strides_as(ctypes.c_longlong)
  2117. <numpy.core._internal.c_longlong_Array_2 object at 0x01F01300>
  2118. """))
  2119. add_newdoc('numpy.core.multiarray', 'ndarray', ('data',
  2120. """Python buffer object pointing to the start of the array's data."""))
  2121. add_newdoc('numpy.core.multiarray', 'ndarray', ('dtype',
  2122. """
  2123. Data-type of the array's elements.
  2124. Parameters
  2125. ----------
  2126. None
  2127. Returns
  2128. -------
  2129. d : numpy dtype object
  2130. See Also
  2131. --------
  2132. numpy.dtype
  2133. Examples
  2134. --------
  2135. >>> x
  2136. array([[0, 1],
  2137. [2, 3]])
  2138. >>> x.dtype
  2139. dtype('int32')
  2140. >>> type(x.dtype)
  2141. <type 'numpy.dtype'>
  2142. """))
  2143. add_newdoc('numpy.core.multiarray', 'ndarray', ('imag',
  2144. """
  2145. The imaginary part of the array.
  2146. Examples
  2147. --------
  2148. >>> x = np.sqrt([1+0j, 0+1j])
  2149. >>> x.imag
  2150. array([ 0. , 0.70710678])
  2151. >>> x.imag.dtype
  2152. dtype('float64')
  2153. """))
  2154. add_newdoc('numpy.core.multiarray', 'ndarray', ('itemsize',
  2155. """
  2156. Length of one array element in bytes.
  2157. Examples
  2158. --------
  2159. >>> x = np.array([1,2,3], dtype=np.float64)
  2160. >>> x.itemsize
  2161. 8
  2162. >>> x = np.array([1,2,3], dtype=np.complex128)
  2163. >>> x.itemsize
  2164. 16
  2165. """))
  2166. add_newdoc('numpy.core.multiarray', 'ndarray', ('flags',
  2167. """
  2168. Information about the memory layout of the array.
  2169. Attributes
  2170. ----------
  2171. C_CONTIGUOUS (C)
  2172. The data is in a single, C-style contiguous segment.
  2173. F_CONTIGUOUS (F)
  2174. The data is in a single, Fortran-style contiguous segment.
  2175. OWNDATA (O)
  2176. The array owns the memory it uses or borrows it from another object.
  2177. WRITEABLE (W)
  2178. The data area can be written to. Setting this to False locks
  2179. the data, making it read-only. A view (slice, etc.) inherits WRITEABLE
  2180. from its base array at creation time, but a view of a writeable
  2181. array may be subsequently locked while the base array remains writeable.
  2182. (The opposite is not true, in that a view of a locked array may not
  2183. be made writeable. However, currently, locking a base object does not
  2184. lock any views that already reference it, so under that circumstance it
  2185. is possible to alter the contents of a locked array via a previously
  2186. created writeable view onto it.) Attempting to change a non-writeable
  2187. array raises a RuntimeError exception.
  2188. ALIGNED (A)
  2189. The data and all elements are aligned appropriately for the hardware.
  2190. UPDATEIFCOPY (U)
  2191. This array is a copy of some other array. When this array is
  2192. deallocated, the base array will be updated with the contents of
  2193. this array.
  2194. FNC
  2195. F_CONTIGUOUS and not C_CONTIGUOUS.
  2196. FORC
  2197. F_CONTIGUOUS or C_CONTIGUOUS (one-segment test).
  2198. BEHAVED (B)
  2199. ALIGNED and WRITEABLE.
  2200. CARRAY (CA)
  2201. BEHAVED and C_CONTIGUOUS.
  2202. FARRAY (FA)
  2203. BEHAVED and F_CONTIGUOUS and not C_CONTIGUOUS.
  2204. Notes
  2205. -----
  2206. The `flags` object can be accessed dictionary-like (as in ``a.flags['WRITEABLE']``),
  2207. or by using lowercased attribute names (as in ``a.flags.writeable``). Short flag
  2208. names are only supported in dictionary access.
  2209. Only the UPDATEIFCOPY, WRITEABLE, and ALIGNED flags can be changed by
  2210. the user, via direct assignment to the attribute or dictionary entry,
  2211. or by calling `ndarray.setflags`.
  2212. The array flags cannot be set arbitrarily:
  2213. - UPDATEIFCOPY can only be set ``False``.
  2214. - ALIGNED can only be set ``True`` if the data is truly aligned.
  2215. - WRITEABLE can only be set ``True`` if the array owns its own memory
  2216. or the ultimate owner of the memory exposes a writeable buffer
  2217. interface or is a string.
  2218. Arrays can be both C-style and Fortran-style contiguous simultaneously.
  2219. This is clear for 1-dimensional arrays, but can also be true for higher
  2220. dimensional arrays.
  2221. Even for contiguous arrays a stride for a given dimension
  2222. ``arr.strides[dim]`` may be *arbitrary* if ``arr.shape[dim] == 1``
  2223. or the array has no elements.
  2224. It does *not* generally hold that ``self.strides[-1] == self.itemsize``
  2225. for C-style contiguous arrays or ``self.strides[0] == self.itemsize`` for
  2226. Fortran-style contiguous arrays is true.
  2227. """))
  2228. add_newdoc('numpy.core.multiarray', 'ndarray', ('flat',
  2229. """
  2230. A 1-D iterator over the array.
  2231. This is a `numpy.flatiter` instance, which acts similarly to, but is not
  2232. a subclass of, Python's built-in iterator object.
  2233. See Also
  2234. --------
  2235. flatten : Return a copy of the array collapsed into one dimension.
  2236. flatiter
  2237. Examples
  2238. --------
  2239. >>> x = np.arange(1, 7).reshape(2, 3)
  2240. >>> x
  2241. array([[1, 2, 3],
  2242. [4, 5, 6]])
  2243. >>> x.flat[3]
  2244. 4
  2245. >>> x.T
  2246. array([[1, 4],
  2247. [2, 5],
  2248. [3, 6]])
  2249. >>> x.T.flat[3]
  2250. 5
  2251. >>> type(x.flat)
  2252. <type 'numpy.flatiter'>
  2253. An assignment example:
  2254. >>> x.flat = 3; x
  2255. array([[3, 3, 3],
  2256. [3, 3, 3]])
  2257. >>> x.flat[[1,4]] = 1; x
  2258. array([[3, 1, 3],
  2259. [3, 1, 3]])
  2260. """))
  2261. add_newdoc('numpy.core.multiarray', 'ndarray', ('nbytes',
  2262. """
  2263. Total bytes consumed by the elements of the array.
  2264. Notes
  2265. -----
  2266. Does not include memory consumed by non-element attributes of the
  2267. array object.
  2268. Examples
  2269. --------
  2270. >>> x = np.zeros((3,5,2), dtype=np.complex128)
  2271. >>> x.nbytes
  2272. 480
  2273. >>> np.prod(x.shape) * x.itemsize
  2274. 480
  2275. """))
  2276. add_newdoc('numpy.core.multiarray', 'ndarray', ('ndim',
  2277. """
  2278. Number of array dimensions.
  2279. Examples
  2280. --------
  2281. >>> x = np.array([1, 2, 3])
  2282. >>> x.ndim
  2283. 1
  2284. >>> y = np.zeros((2, 3, 4))
  2285. >>> y.ndim
  2286. 3
  2287. """))
  2288. add_newdoc('numpy.core.multiarray', 'ndarray', ('real',
  2289. """
  2290. The real part of the array.
  2291. Examples
  2292. --------
  2293. >>> x = np.sqrt([1+0j, 0+1j])
  2294. >>> x.real
  2295. array([ 1. , 0.70710678])
  2296. >>> x.real.dtype
  2297. dtype('float64')
  2298. See Also
  2299. --------
  2300. numpy.real : equivalent function
  2301. """))
  2302. add_newdoc('numpy.core.multiarray', 'ndarray', ('shape',
  2303. """
  2304. Tuple of array dimensions.
  2305. Notes
  2306. -----
  2307. May be used to "reshape" the array, as long as this would not
  2308. require a change in the total number of elements
  2309. Examples
  2310. --------
  2311. >>> x = np.array([1, 2, 3, 4])
  2312. >>> x.shape
  2313. (4,)
  2314. >>> y = np.zeros((2, 3, 4))
  2315. >>> y.shape
  2316. (2, 3, 4)
  2317. >>> y.shape = (3, 8)
  2318. >>> y
  2319. array([[ 0., 0., 0., 0., 0., 0., 0., 0.],
  2320. [ 0., 0., 0., 0., 0., 0., 0., 0.],
  2321. [ 0., 0., 0., 0., 0., 0., 0., 0.]])
  2322. >>> y.shape = (3, 6)
  2323. Traceback (most recent call last):
  2324. File "<stdin>", line 1, in <module>
  2325. ValueError: total size of new array must be unchanged
  2326. """))
  2327. add_newdoc('numpy.core.multiarray', 'ndarray', ('size',
  2328. """
  2329. Number of elements in the array.
  2330. Equivalent to ``np.prod(a.shape)``, i.e., the product of the array's
  2331. dimensions.
  2332. Examples
  2333. --------
  2334. >>> x = np.zeros((3, 5, 2), dtype=np.complex128)
  2335. >>> x.size
  2336. 30
  2337. >>> np.prod(x.shape)
  2338. 30
  2339. """))
  2340. add_newdoc('numpy.core.multiarray', 'ndarray', ('strides',
  2341. """
  2342. Tuple of bytes to step in each dimension when traversing an array.
  2343. The byte offset of element ``(i[0], i[1], ..., i[n])`` in an array `a`
  2344. is::
  2345. offset = sum(np.array(i) * a.strides)
  2346. A more detailed explanation of strides can be found in the
  2347. "ndarray.rst" file in the NumPy reference guide.
  2348. Notes
  2349. -----
  2350. Imagine an array of 32-bit integers (each 4 bytes)::
  2351. x = np.array([[0, 1, 2, 3, 4],
  2352. [5, 6, 7, 8, 9]], dtype=np.int32)
  2353. This array is stored in memory as 40 bytes, one after the other
  2354. (known as a contiguous block of memory). The strides of an array tell
  2355. us how many bytes we have to skip in memory to move to the next position
  2356. along a certain axis. For example, we have to skip 4 bytes (1 value) to
  2357. move to the next column, but 20 bytes (5 values) to get to the same
  2358. position in the next row. As such, the strides for the array `x` will be
  2359. ``(20, 4)``.
  2360. See Also
  2361. --------
  2362. numpy.lib.stride_tricks.as_strided
  2363. Examples
  2364. --------
  2365. >>> y = np.reshape(np.arange(2*3*4), (2,3,4))
  2366. >>> y
  2367. array([[[ 0, 1, 2, 3],
  2368. [ 4, 5, 6, 7],
  2369. [ 8, 9, 10, 11]],
  2370. [[12, 13, 14, 15],
  2371. [16, 17, 18, 19],
  2372. [20, 21, 22, 23]]])
  2373. >>> y.strides
  2374. (48, 16, 4)
  2375. >>> y[1,1,1]
  2376. 17
  2377. >>> offset=sum(y.strides * np.array((1,1,1)))
  2378. >>> offset/y.itemsize
  2379. 17
  2380. >>> x = np.reshape(np.arange(5*6*7*8), (5,6,7,8)).transpose(2,3,1,0)
  2381. >>> x.strides
  2382. (32, 4, 224, 1344)
  2383. >>> i = np.array([3,5,2,2])
  2384. >>> offset = sum(i * x.strides)
  2385. >>> x[3,5,2,2]
  2386. 813
  2387. >>> offset / x.itemsize
  2388. 813
  2389. """))
  2390. add_newdoc('numpy.core.multiarray', 'ndarray', ('T',
  2391. """
  2392. Same as self.transpose(), except that self is returned if
  2393. self.ndim < 2.
  2394. Examples
  2395. --------
  2396. >>> x = np.array([[1.,2.],[3.,4.]])
  2397. >>> x
  2398. array([[ 1., 2.],
  2399. [ 3., 4.]])
  2400. >>> x.T
  2401. array([[ 1., 3.],
  2402. [ 2., 4.]])
  2403. >>> x = np.array([1.,2.,3.,4.])
  2404. >>> x
  2405. array([ 1., 2., 3., 4.])
  2406. >>> x.T
  2407. array([ 1., 2., 3., 4.])
  2408. """))
  2409. ##############################################################################
  2410. #
  2411. # ndarray methods
  2412. #
  2413. ##############################################################################
  2414. add_newdoc('numpy.core.multiarray', 'ndarray', ('__array__',
  2415. """ a.__array__(|dtype) -> reference if type unchanged, copy otherwise.
  2416. Returns either a new reference to self if dtype is not given or a new array
  2417. of provided data type if dtype is different from the current dtype of the
  2418. array.
  2419. """))
  2420. add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_prepare__',
  2421. """a.__array_prepare__(obj) -> Object of same type as ndarray object obj.
  2422. """))
  2423. add_newdoc('numpy.core.multiarray', 'ndarray', ('__array_wrap__',
  2424. """a.__array_wrap__(obj) -> Object of same type as ndarray object a.
  2425. """))
  2426. add_newdoc('numpy.core.multiarray', 'ndarray', ('__copy__',
  2427. """a.__copy__([order])
  2428. Return a copy of the array.
  2429. Parameters
  2430. ----------
  2431. order : {'C', 'F', 'A'}, optional
  2432. If order is 'C' (False) then the result is contiguous (default).
  2433. If order is 'Fortran' (True) then the result has fortran order.
  2434. If order is 'Any' (None) then the result has fortran order
  2435. only if the array already is in fortran order.
  2436. """))
  2437. add_newdoc('numpy.core.multiarray', 'ndarray', ('__deepcopy__',
  2438. """a.__deepcopy__() -> Deep copy of array.
  2439. Used if copy.deepcopy is called on an array.
  2440. """))
  2441. add_newdoc('numpy.core.multiarray', 'ndarray', ('__reduce__',
  2442. """a.__reduce__()
  2443. For pickling.
  2444. """))
  2445. add_newdoc('numpy.core.multiarray', 'ndarray', ('__setstate__',
  2446. """a.__setstate__(version, shape, dtype, isfortran, rawdata)
  2447. For unpickling.
  2448. Parameters
  2449. ----------
  2450. version : int
  2451. optional pickle version. If omitted defaults to 0.
  2452. shape : tuple
  2453. dtype : data-type
  2454. isFortran : bool
  2455. rawdata : string or list
  2456. a binary string with the data (or a list if 'a' is an object array)
  2457. """))
  2458. add_newdoc('numpy.core.multiarray', 'ndarray', ('all',
  2459. """
  2460. a.all(axis=None, out=None, keepdims=False)
  2461. Returns True if all elements evaluate to True.
  2462. Refer to `numpy.all` for full documentation.
  2463. See Also
  2464. --------
  2465. numpy.all : equivalent function
  2466. """))
  2467. add_newdoc('numpy.core.multiarray', 'ndarray', ('any',
  2468. """
  2469. a.any(axis=None, out=None, keepdims=False)
  2470. Returns True if any of the elements of `a` evaluate to True.
  2471. Refer to `numpy.any` for full documentation.
  2472. See Also
  2473. --------
  2474. numpy.any : equivalent function
  2475. """))
  2476. add_newdoc('numpy.core.multiarray', 'ndarray', ('argmax',
  2477. """
  2478. a.argmax(axis=None, out=None)
  2479. Return indices of the maximum values along the given axis.
  2480. Refer to `numpy.argmax` for full documentation.
  2481. See Also
  2482. --------
  2483. numpy.argmax : equivalent function
  2484. """))
  2485. add_newdoc('numpy.core.multiarray', 'ndarray', ('argmin',
  2486. """
  2487. a.argmin(axis=None, out=None)
  2488. Return indices of the minimum values along the given axis of `a`.
  2489. Refer to `numpy.argmin` for detailed documentation.
  2490. See Also
  2491. --------
  2492. numpy.argmin : equivalent function
  2493. """))
  2494. add_newdoc('numpy.core.multiarray', 'ndarray', ('argsort',
  2495. """
  2496. a.argsort(axis=-1, kind='quicksort', order=None)
  2497. Returns the indices that would sort this array.
  2498. Refer to `numpy.argsort` for full documentation.
  2499. See Also
  2500. --------
  2501. numpy.argsort : equivalent function
  2502. """))
  2503. add_newdoc('numpy.core.multiarray', 'ndarray', ('argpartition',
  2504. """
  2505. a.argpartition(kth, axis=-1, kind='introselect', order=None)
  2506. Returns the indices that would partition this array.
  2507. Refer to `numpy.argpartition` for full documentation.
  2508. .. versionadded:: 1.8.0
  2509. See Also
  2510. --------
  2511. numpy.argpartition : equivalent function
  2512. """))
  2513. add_newdoc('numpy.core.multiarray', 'ndarray', ('astype',
  2514. """
  2515. a.astype(dtype, order='K', casting='unsafe', subok=True, copy=True)
  2516. Copy of the array, cast to a specified type.
  2517. Parameters
  2518. ----------
  2519. dtype : str or dtype
  2520. Typecode or data-type to which the array is cast.
  2521. order : {'C', 'F', 'A', 'K'}, optional
  2522. Controls the memory layout order of the result.
  2523. 'C' means C order, 'F' means Fortran order, 'A'
  2524. means 'F' order if all the arrays are Fortran contiguous,
  2525. 'C' order otherwise, and 'K' means as close to the
  2526. order the array elements appear in memory as possible.
  2527. Default is 'K'.
  2528. casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
  2529. Controls what kind of data casting may occur. Defaults to 'unsafe'
  2530. for backwards compatibility.
  2531. * 'no' means the data types should not be cast at all.
  2532. * 'equiv' means only byte-order changes are allowed.
  2533. * 'safe' means only casts which can preserve values are allowed.
  2534. * 'same_kind' means only safe casts or casts within a kind,
  2535. like float64 to float32, are allowed.
  2536. * 'unsafe' means any data conversions may be done.
  2537. subok : bool, optional
  2538. If True, then sub-classes will be passed-through (default), otherwise
  2539. the returned array will be forced to be a base-class array.
  2540. copy : bool, optional
  2541. By default, astype always returns a newly allocated array. If this
  2542. is set to false, and the `dtype`, `order`, and `subok`
  2543. requirements are satisfied, the input array is returned instead
  2544. of a copy.
  2545. Returns
  2546. -------
  2547. arr_t : ndarray
  2548. Unless `copy` is False and the other conditions for returning the input
  2549. array are satisfied (see description for `copy` input parameter), `arr_t`
  2550. is a new array of the same shape as the input array, with dtype, order
  2551. given by `dtype`, `order`.
  2552. Notes
  2553. -----
  2554. Starting in NumPy 1.9, astype method now returns an error if the string
  2555. dtype to cast to is not long enough in 'safe' casting mode to hold the max
  2556. value of integer/float array that is being casted. Previously the casting
  2557. was allowed even if the result was truncated.
  2558. Raises
  2559. ------
  2560. ComplexWarning
  2561. When casting from complex to float or int. To avoid this,
  2562. one should use ``a.real.astype(t)``.
  2563. Examples
  2564. --------
  2565. >>> x = np.array([1, 2, 2.5])
  2566. >>> x
  2567. array([ 1. , 2. , 2.5])
  2568. >>> x.astype(int)
  2569. array([1, 2, 2])
  2570. """))
  2571. add_newdoc('numpy.core.multiarray', 'ndarray', ('byteswap',
  2572. """
  2573. a.byteswap(inplace)
  2574. Swap the bytes of the array elements
  2575. Toggle between low-endian and big-endian data representation by
  2576. returning a byteswapped array, optionally swapped in-place.
  2577. Parameters
  2578. ----------
  2579. inplace : bool, optional
  2580. If ``True``, swap bytes in-place, default is ``False``.
  2581. Returns
  2582. -------
  2583. out : ndarray
  2584. The byteswapped array. If `inplace` is ``True``, this is
  2585. a view to self.
  2586. Examples
  2587. --------
  2588. >>> A = np.array([1, 256, 8755], dtype=np.int16)
  2589. >>> map(hex, A)
  2590. ['0x1', '0x100', '0x2233']
  2591. >>> A.byteswap(True)
  2592. array([ 256, 1, 13090], dtype=int16)
  2593. >>> map(hex, A)
  2594. ['0x100', '0x1', '0x3322']
  2595. Arrays of strings are not swapped
  2596. >>> A = np.array(['ceg', 'fac'])
  2597. >>> A.byteswap()
  2598. array(['ceg', 'fac'],
  2599. dtype='|S3')
  2600. """))
  2601. add_newdoc('numpy.core.multiarray', 'ndarray', ('choose',
  2602. """
  2603. a.choose(choices, out=None, mode='raise')
  2604. Use an index array to construct a new array from a set of choices.
  2605. Refer to `numpy.choose` for full documentation.
  2606. See Also
  2607. --------
  2608. numpy.choose : equivalent function
  2609. """))
  2610. add_newdoc('numpy.core.multiarray', 'ndarray', ('clip',
  2611. """
  2612. a.clip(min=None, max=None, out=None)
  2613. Return an array whose values are limited to ``[min, max]``.
  2614. One of max or min must be given.
  2615. Refer to `numpy.clip` for full documentation.
  2616. See Also
  2617. --------
  2618. numpy.clip : equivalent function
  2619. """))
  2620. add_newdoc('numpy.core.multiarray', 'ndarray', ('compress',
  2621. """
  2622. a.compress(condition, axis=None, out=None)
  2623. Return selected slices of this array along given axis.
  2624. Refer to `numpy.compress` for full documentation.
  2625. See Also
  2626. --------
  2627. numpy.compress : equivalent function
  2628. """))
  2629. add_newdoc('numpy.core.multiarray', 'ndarray', ('conj',
  2630. """
  2631. a.conj()
  2632. Complex-conjugate all elements.
  2633. Refer to `numpy.conjugate` for full documentation.
  2634. See Also
  2635. --------
  2636. numpy.conjugate : equivalent function
  2637. """))
  2638. add_newdoc('numpy.core.multiarray', 'ndarray', ('conjugate',
  2639. """
  2640. a.conjugate()
  2641. Return the complex conjugate, element-wise.
  2642. Refer to `numpy.conjugate` for full documentation.
  2643. See Also
  2644. --------
  2645. numpy.conjugate : equivalent function
  2646. """))
  2647. add_newdoc('numpy.core.multiarray', 'ndarray', ('copy',
  2648. """
  2649. a.copy(order='C')
  2650. Return a copy of the array.
  2651. Parameters
  2652. ----------
  2653. order : {'C', 'F', 'A', 'K'}, optional
  2654. Controls the memory layout of the copy. 'C' means C-order,
  2655. 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
  2656. 'C' otherwise. 'K' means match the layout of `a` as closely
  2657. as possible. (Note that this function and :func:numpy.copy are very
  2658. similar, but have different default values for their order=
  2659. arguments.)
  2660. See also
  2661. --------
  2662. numpy.copy
  2663. numpy.copyto
  2664. Examples
  2665. --------
  2666. >>> x = np.array([[1,2,3],[4,5,6]], order='F')
  2667. >>> y = x.copy()
  2668. >>> x.fill(0)
  2669. >>> x
  2670. array([[0, 0, 0],
  2671. [0, 0, 0]])
  2672. >>> y
  2673. array([[1, 2, 3],
  2674. [4, 5, 6]])
  2675. >>> y.flags['C_CONTIGUOUS']
  2676. True
  2677. """))
  2678. add_newdoc('numpy.core.multiarray', 'ndarray', ('cumprod',
  2679. """
  2680. a.cumprod(axis=None, dtype=None, out=None)
  2681. Return the cumulative product of the elements along the given axis.
  2682. Refer to `numpy.cumprod` for full documentation.
  2683. See Also
  2684. --------
  2685. numpy.cumprod : equivalent function
  2686. """))
  2687. add_newdoc('numpy.core.multiarray', 'ndarray', ('cumsum',
  2688. """
  2689. a.cumsum(axis=None, dtype=None, out=None)
  2690. Return the cumulative sum of the elements along the given axis.
  2691. Refer to `numpy.cumsum` for full documentation.
  2692. See Also
  2693. --------
  2694. numpy.cumsum : equivalent function
  2695. """))
  2696. add_newdoc('numpy.core.multiarray', 'ndarray', ('diagonal',
  2697. """
  2698. a.diagonal(offset=0, axis1=0, axis2=1)
  2699. Return specified diagonals. In NumPy 1.9 the returned array is a
  2700. read-only view instead of a copy as in previous NumPy versions. In
  2701. a future version the read-only restriction will be removed.
  2702. Refer to :func:`numpy.diagonal` for full documentation.
  2703. See Also
  2704. --------
  2705. numpy.diagonal : equivalent function
  2706. """))
  2707. add_newdoc('numpy.core.multiarray', 'ndarray', ('dot',
  2708. """
  2709. a.dot(b, out=None)
  2710. Dot product of two arrays.
  2711. Refer to `numpy.dot` for full documentation.
  2712. See Also
  2713. --------
  2714. numpy.dot : equivalent function
  2715. Examples
  2716. --------
  2717. >>> a = np.eye(2)
  2718. >>> b = np.ones((2, 2)) * 2
  2719. >>> a.dot(b)
  2720. array([[ 2., 2.],
  2721. [ 2., 2.]])
  2722. This array method can be conveniently chained:
  2723. >>> a.dot(b).dot(b)
  2724. array([[ 8., 8.],
  2725. [ 8., 8.]])
  2726. """))
  2727. add_newdoc('numpy.core.multiarray', 'ndarray', ('dump',
  2728. """a.dump(file)
  2729. Dump a pickle of the array to the specified file.
  2730. The array can be read back with pickle.load or numpy.load.
  2731. Parameters
  2732. ----------
  2733. file : str
  2734. A string naming the dump file.
  2735. """))
  2736. add_newdoc('numpy.core.multiarray', 'ndarray', ('dumps',
  2737. """
  2738. a.dumps()
  2739. Returns the pickle of the array as a string.
  2740. pickle.loads or numpy.loads will convert the string back to an array.
  2741. Parameters
  2742. ----------
  2743. None
  2744. """))
  2745. add_newdoc('numpy.core.multiarray', 'ndarray', ('fill',
  2746. """
  2747. a.fill(value)
  2748. Fill the array with a scalar value.
  2749. Parameters
  2750. ----------
  2751. value : scalar
  2752. All elements of `a` will be assigned this value.
  2753. Examples
  2754. --------
  2755. >>> a = np.array([1, 2])
  2756. >>> a.fill(0)
  2757. >>> a
  2758. array([0, 0])
  2759. >>> a = np.empty(2)
  2760. >>> a.fill(1)
  2761. >>> a
  2762. array([ 1., 1.])
  2763. """))
  2764. add_newdoc('numpy.core.multiarray', 'ndarray', ('flatten',
  2765. """
  2766. a.flatten(order='C')
  2767. Return a copy of the array collapsed into one dimension.
  2768. Parameters
  2769. ----------
  2770. order : {'C', 'F', 'A', 'K'}, optional
  2771. 'C' means to flatten in row-major (C-style) order.
  2772. 'F' means to flatten in column-major (Fortran-
  2773. style) order. 'A' means to flatten in column-major
  2774. order if `a` is Fortran *contiguous* in memory,
  2775. row-major order otherwise. 'K' means to flatten
  2776. `a` in the order the elements occur in memory.
  2777. The default is 'C'.
  2778. Returns
  2779. -------
  2780. y : ndarray
  2781. A copy of the input array, flattened to one dimension.
  2782. See Also
  2783. --------
  2784. ravel : Return a flattened array.
  2785. flat : A 1-D flat iterator over the array.
  2786. Examples
  2787. --------
  2788. >>> a = np.array([[1,2], [3,4]])
  2789. >>> a.flatten()
  2790. array([1, 2, 3, 4])
  2791. >>> a.flatten('F')
  2792. array([1, 3, 2, 4])
  2793. """))
  2794. add_newdoc('numpy.core.multiarray', 'ndarray', ('getfield',
  2795. """
  2796. a.getfield(dtype, offset=0)
  2797. Returns a field of the given array as a certain type.
  2798. A field is a view of the array data with a given data-type. The values in
  2799. the view are determined by the given type and the offset into the current
  2800. array in bytes. The offset needs to be such that the view dtype fits in the
  2801. array dtype; for example an array of dtype complex128 has 16-byte elements.
  2802. If taking a view with a 32-bit integer (4 bytes), the offset needs to be
  2803. between 0 and 12 bytes.
  2804. Parameters
  2805. ----------
  2806. dtype : str or dtype
  2807. The data type of the view. The dtype size of the view can not be larger
  2808. than that of the array itself.
  2809. offset : int
  2810. Number of bytes to skip before beginning the element view.
  2811. Examples
  2812. --------
  2813. >>> x = np.diag([1.+1.j]*2)
  2814. >>> x[1, 1] = 2 + 4.j
  2815. >>> x
  2816. array([[ 1.+1.j, 0.+0.j],
  2817. [ 0.+0.j, 2.+4.j]])
  2818. >>> x.getfield(np.float64)
  2819. array([[ 1., 0.],
  2820. [ 0., 2.]])
  2821. By choosing an offset of 8 bytes we can select the complex part of the
  2822. array for our view:
  2823. >>> x.getfield(np.float64, offset=8)
  2824. array([[ 1., 0.],
  2825. [ 0., 4.]])
  2826. """))
  2827. add_newdoc('numpy.core.multiarray', 'ndarray', ('item',
  2828. """
  2829. a.item(*args)
  2830. Copy an element of an array to a standard Python scalar and return it.
  2831. Parameters
  2832. ----------
  2833. \\*args : Arguments (variable number and type)
  2834. * none: in this case, the method only works for arrays
  2835. with one element (`a.size == 1`), which element is
  2836. copied into a standard Python scalar object and returned.
  2837. * int_type: this argument is interpreted as a flat index into
  2838. the array, specifying which element to copy and return.
  2839. * tuple of int_types: functions as does a single int_type argument,
  2840. except that the argument is interpreted as an nd-index into the
  2841. array.
  2842. Returns
  2843. -------
  2844. z : Standard Python scalar object
  2845. A copy of the specified element of the array as a suitable
  2846. Python scalar
  2847. Notes
  2848. -----
  2849. When the data type of `a` is longdouble or clongdouble, item() returns
  2850. a scalar array object because there is no available Python scalar that
  2851. would not lose information. Void arrays return a buffer object for item(),
  2852. unless fields are defined, in which case a tuple is returned.
  2853. `item` is very similar to a[args], except, instead of an array scalar,
  2854. a standard Python scalar is returned. This can be useful for speeding up
  2855. access to elements of the array and doing arithmetic on elements of the
  2856. array using Python's optimized math.
  2857. Examples
  2858. --------
  2859. >>> x = np.random.randint(9, size=(3, 3))
  2860. >>> x
  2861. array([[3, 1, 7],
  2862. [2, 8, 3],
  2863. [8, 5, 3]])
  2864. >>> x.item(3)
  2865. 2
  2866. >>> x.item(7)
  2867. 5
  2868. >>> x.item((0, 1))
  2869. 1
  2870. >>> x.item((2, 2))
  2871. 3
  2872. """))
  2873. add_newdoc('numpy.core.multiarray', 'ndarray', ('itemset',
  2874. """
  2875. a.itemset(*args)
  2876. Insert scalar into an array (scalar is cast to array's dtype, if possible)
  2877. There must be at least 1 argument, and define the last argument
  2878. as *item*. Then, ``a.itemset(*args)`` is equivalent to but faster
  2879. than ``a[args] = item``. The item should be a scalar value and `args`
  2880. must select a single item in the array `a`.
  2881. Parameters
  2882. ----------
  2883. \*args : Arguments
  2884. If one argument: a scalar, only used in case `a` is of size 1.
  2885. If two arguments: the last argument is the value to be set
  2886. and must be a scalar, the first argument specifies a single array
  2887. element location. It is either an int or a tuple.
  2888. Notes
  2889. -----
  2890. Compared to indexing syntax, `itemset` provides some speed increase
  2891. for placing a scalar into a particular location in an `ndarray`,
  2892. if you must do this. However, generally this is discouraged:
  2893. among other problems, it complicates the appearance of the code.
  2894. Also, when using `itemset` (and `item`) inside a loop, be sure
  2895. to assign the methods to a local variable to avoid the attribute
  2896. look-up at each loop iteration.
  2897. Examples
  2898. --------
  2899. >>> x = np.random.randint(9, size=(3, 3))
  2900. >>> x
  2901. array([[3, 1, 7],
  2902. [2, 8, 3],
  2903. [8, 5, 3]])
  2904. >>> x.itemset(4, 0)
  2905. >>> x.itemset((2, 2), 9)
  2906. >>> x
  2907. array([[3, 1, 7],
  2908. [2, 0, 3],
  2909. [8, 5, 9]])
  2910. """))
  2911. add_newdoc('numpy.core.multiarray', 'ndarray', ('max',
  2912. """
  2913. a.max(axis=None, out=None)
  2914. Return the maximum along a given axis.
  2915. Refer to `numpy.amax` for full documentation.
  2916. See Also
  2917. --------
  2918. numpy.amax : equivalent function
  2919. """))
  2920. add_newdoc('numpy.core.multiarray', 'ndarray', ('mean',
  2921. """
  2922. a.mean(axis=None, dtype=None, out=None, keepdims=False)
  2923. Returns the average of the array elements along given axis.
  2924. Refer to `numpy.mean` for full documentation.
  2925. See Also
  2926. --------
  2927. numpy.mean : equivalent function
  2928. """))
  2929. add_newdoc('numpy.core.multiarray', 'ndarray', ('min',
  2930. """
  2931. a.min(axis=None, out=None, keepdims=False)
  2932. Return the minimum along a given axis.
  2933. Refer to `numpy.amin` for full documentation.
  2934. See Also
  2935. --------
  2936. numpy.amin : equivalent function
  2937. """))
  2938. add_newdoc('numpy.core.multiarray', 'shares_memory',
  2939. """
  2940. shares_memory(a, b, max_work=None)
  2941. Determine if two arrays share memory
  2942. Parameters
  2943. ----------
  2944. a, b : ndarray
  2945. Input arrays
  2946. max_work : int, optional
  2947. Effort to spend on solving the overlap problem (maximum number
  2948. of candidate solutions to consider). The following special
  2949. values are recognized:
  2950. max_work=MAY_SHARE_EXACT (default)
  2951. The problem is solved exactly. In this case, the function returns
  2952. True only if there is an element shared between the arrays.
  2953. max_work=MAY_SHARE_BOUNDS
  2954. Only the memory bounds of a and b are checked.
  2955. Raises
  2956. ------
  2957. numpy.TooHardError
  2958. Exceeded max_work.
  2959. Returns
  2960. -------
  2961. out : bool
  2962. See Also
  2963. --------
  2964. may_share_memory
  2965. Examples
  2966. --------
  2967. >>> np.may_share_memory(np.array([1,2]), np.array([5,8,9]))
  2968. False
  2969. """)
  2970. add_newdoc('numpy.core.multiarray', 'may_share_memory',
  2971. """
  2972. may_share_memory(a, b, max_work=None)
  2973. Determine if two arrays might share memory
  2974. A return of True does not necessarily mean that the two arrays
  2975. share any element. It just means that they *might*.
  2976. Only the memory bounds of a and b are checked by default.
  2977. Parameters
  2978. ----------
  2979. a, b : ndarray
  2980. Input arrays
  2981. max_work : int, optional
  2982. Effort to spend on solving the overlap problem. See
  2983. `shares_memory` for details. Default for ``may_share_memory``
  2984. is to do a bounds check.
  2985. Returns
  2986. -------
  2987. out : bool
  2988. See Also
  2989. --------
  2990. shares_memory
  2991. Examples
  2992. --------
  2993. >>> np.may_share_memory(np.array([1,2]), np.array([5,8,9]))
  2994. False
  2995. >>> x = np.zeros([3, 4])
  2996. >>> np.may_share_memory(x[:,0], x[:,1])
  2997. True
  2998. """)
  2999. add_newdoc('numpy.core.multiarray', 'ndarray', ('newbyteorder',
  3000. """
  3001. arr.newbyteorder(new_order='S')
  3002. Return the array with the same data viewed with a different byte order.
  3003. Equivalent to::
  3004. arr.view(arr.dtype.newbytorder(new_order))
  3005. Changes are also made in all fields and sub-arrays of the array data
  3006. type.
  3007. Parameters
  3008. ----------
  3009. new_order : string, optional
  3010. Byte order to force; a value from the byte order specifications
  3011. below. `new_order` codes can be any of:
  3012. * 'S' - swap dtype from current to opposite endian
  3013. * {'<', 'L'} - little endian
  3014. * {'>', 'B'} - big endian
  3015. * {'=', 'N'} - native order
  3016. * {'|', 'I'} - ignore (no change to byte order)
  3017. The default value ('S') results in swapping the current
  3018. byte order. The code does a case-insensitive check on the first
  3019. letter of `new_order` for the alternatives above. For example,
  3020. any of 'B' or 'b' or 'biggish' are valid to specify big-endian.
  3021. Returns
  3022. -------
  3023. new_arr : array
  3024. New array object with the dtype reflecting given change to the
  3025. byte order.
  3026. """))
  3027. add_newdoc('numpy.core.multiarray', 'ndarray', ('nonzero',
  3028. """
  3029. a.nonzero()
  3030. Return the indices of the elements that are non-zero.
  3031. Refer to `numpy.nonzero` for full documentation.
  3032. See Also
  3033. --------
  3034. numpy.nonzero : equivalent function
  3035. """))
  3036. add_newdoc('numpy.core.multiarray', 'ndarray', ('prod',
  3037. """
  3038. a.prod(axis=None, dtype=None, out=None, keepdims=False)
  3039. Return the product of the array elements over the given axis
  3040. Refer to `numpy.prod` for full documentation.
  3041. See Also
  3042. --------
  3043. numpy.prod : equivalent function
  3044. """))
  3045. add_newdoc('numpy.core.multiarray', 'ndarray', ('ptp',
  3046. """
  3047. a.ptp(axis=None, out=None)
  3048. Peak to peak (maximum - minimum) value along a given axis.
  3049. Refer to `numpy.ptp` for full documentation.
  3050. See Also
  3051. --------
  3052. numpy.ptp : equivalent function
  3053. """))
  3054. add_newdoc('numpy.core.multiarray', 'ndarray', ('put',
  3055. """
  3056. a.put(indices, values, mode='raise')
  3057. Set ``a.flat[n] = values[n]`` for all `n` in indices.
  3058. Refer to `numpy.put` for full documentation.
  3059. See Also
  3060. --------
  3061. numpy.put : equivalent function
  3062. """))
  3063. add_newdoc('numpy.core.multiarray', 'copyto',
  3064. """
  3065. copyto(dst, src, casting='same_kind', where=None)
  3066. Copies values from one array to another, broadcasting as necessary.
  3067. Raises a TypeError if the `casting` rule is violated, and if
  3068. `where` is provided, it selects which elements to copy.
  3069. .. versionadded:: 1.7.0
  3070. Parameters
  3071. ----------
  3072. dst : ndarray
  3073. The array into which values are copied.
  3074. src : array_like
  3075. The array from which values are copied.
  3076. casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
  3077. Controls what kind of data casting may occur when copying.
  3078. * 'no' means the data types should not be cast at all.
  3079. * 'equiv' means only byte-order changes are allowed.
  3080. * 'safe' means only casts which can preserve values are allowed.
  3081. * 'same_kind' means only safe casts or casts within a kind,
  3082. like float64 to float32, are allowed.
  3083. * 'unsafe' means any data conversions may be done.
  3084. where : array_like of bool, optional
  3085. A boolean array which is broadcasted to match the dimensions
  3086. of `dst`, and selects elements to copy from `src` to `dst`
  3087. wherever it contains the value True.
  3088. """)
  3089. add_newdoc('numpy.core.multiarray', 'putmask',
  3090. """
  3091. putmask(a, mask, values)
  3092. Changes elements of an array based on conditional and input values.
  3093. Sets ``a.flat[n] = values[n]`` for each n where ``mask.flat[n]==True``.
  3094. If `values` is not the same size as `a` and `mask` then it will repeat.
  3095. This gives behavior different from ``a[mask] = values``.
  3096. Parameters
  3097. ----------
  3098. a : array_like
  3099. Target array.
  3100. mask : array_like
  3101. Boolean mask array. It has to be the same shape as `a`.
  3102. values : array_like
  3103. Values to put into `a` where `mask` is True. If `values` is smaller
  3104. than `a` it will be repeated.
  3105. See Also
  3106. --------
  3107. place, put, take, copyto
  3108. Examples
  3109. --------
  3110. >>> x = np.arange(6).reshape(2, 3)
  3111. >>> np.putmask(x, x>2, x**2)
  3112. >>> x
  3113. array([[ 0, 1, 2],
  3114. [ 9, 16, 25]])
  3115. If `values` is smaller than `a` it is repeated:
  3116. >>> x = np.arange(5)
  3117. >>> np.putmask(x, x>1, [-33, -44])
  3118. >>> x
  3119. array([ 0, 1, -33, -44, -33])
  3120. """)
  3121. add_newdoc('numpy.core.multiarray', 'ndarray', ('ravel',
  3122. """
  3123. a.ravel([order])
  3124. Return a flattened array.
  3125. Refer to `numpy.ravel` for full documentation.
  3126. See Also
  3127. --------
  3128. numpy.ravel : equivalent function
  3129. ndarray.flat : a flat iterator on the array.
  3130. """))
  3131. add_newdoc('numpy.core.multiarray', 'ndarray', ('repeat',
  3132. """
  3133. a.repeat(repeats, axis=None)
  3134. Repeat elements of an array.
  3135. Refer to `numpy.repeat` for full documentation.
  3136. See Also
  3137. --------
  3138. numpy.repeat : equivalent function
  3139. """))
  3140. add_newdoc('numpy.core.multiarray', 'ndarray', ('reshape',
  3141. """
  3142. a.reshape(shape, order='C')
  3143. Returns an array containing the same data with a new shape.
  3144. Refer to `numpy.reshape` for full documentation.
  3145. See Also
  3146. --------
  3147. numpy.reshape : equivalent function
  3148. """))
  3149. add_newdoc('numpy.core.multiarray', 'ndarray', ('resize',
  3150. """
  3151. a.resize(new_shape, refcheck=True)
  3152. Change shape and size of array in-place.
  3153. Parameters
  3154. ----------
  3155. new_shape : tuple of ints, or `n` ints
  3156. Shape of resized array.
  3157. refcheck : bool, optional
  3158. If False, reference count will not be checked. Default is True.
  3159. Returns
  3160. -------
  3161. None
  3162. Raises
  3163. ------
  3164. ValueError
  3165. If `a` does not own its own data or references or views to it exist,
  3166. and the data memory must be changed.
  3167. SystemError
  3168. If the `order` keyword argument is specified. This behaviour is a
  3169. bug in NumPy.
  3170. See Also
  3171. --------
  3172. resize : Return a new array with the specified shape.
  3173. Notes
  3174. -----
  3175. This reallocates space for the data area if necessary.
  3176. Only contiguous arrays (data elements consecutive in memory) can be
  3177. resized.
  3178. The purpose of the reference count check is to make sure you
  3179. do not use this array as a buffer for another Python object and then
  3180. reallocate the memory. However, reference counts can increase in
  3181. other ways so if you are sure that you have not shared the memory
  3182. for this array with another Python object, then you may safely set
  3183. `refcheck` to False.
  3184. Examples
  3185. --------
  3186. Shrinking an array: array is flattened (in the order that the data are
  3187. stored in memory), resized, and reshaped:
  3188. >>> a = np.array([[0, 1], [2, 3]], order='C')
  3189. >>> a.resize((2, 1))
  3190. >>> a
  3191. array([[0],
  3192. [1]])
  3193. >>> a = np.array([[0, 1], [2, 3]], order='F')
  3194. >>> a.resize((2, 1))
  3195. >>> a
  3196. array([[0],
  3197. [2]])
  3198. Enlarging an array: as above, but missing entries are filled with zeros:
  3199. >>> b = np.array([[0, 1], [2, 3]])
  3200. >>> b.resize(2, 3) # new_shape parameter doesn't have to be a tuple
  3201. >>> b
  3202. array([[0, 1, 2],
  3203. [3, 0, 0]])
  3204. Referencing an array prevents resizing...
  3205. >>> c = a
  3206. >>> a.resize((1, 1))
  3207. Traceback (most recent call last):
  3208. ...
  3209. ValueError: cannot resize an array that has been referenced ...
  3210. Unless `refcheck` is False:
  3211. >>> a.resize((1, 1), refcheck=False)
  3212. >>> a
  3213. array([[0]])
  3214. >>> c
  3215. array([[0]])
  3216. """))
  3217. add_newdoc('numpy.core.multiarray', 'ndarray', ('round',
  3218. """
  3219. a.round(decimals=0, out=None)
  3220. Return `a` with each element rounded to the given number of decimals.
  3221. Refer to `numpy.around` for full documentation.
  3222. See Also
  3223. --------
  3224. numpy.around : equivalent function
  3225. """))
  3226. add_newdoc('numpy.core.multiarray', 'ndarray', ('searchsorted',
  3227. """
  3228. a.searchsorted(v, side='left', sorter=None)
  3229. Find indices where elements of v should be inserted in a to maintain order.
  3230. For full documentation, see `numpy.searchsorted`
  3231. See Also
  3232. --------
  3233. numpy.searchsorted : equivalent function
  3234. """))
  3235. add_newdoc('numpy.core.multiarray', 'ndarray', ('setfield',
  3236. """
  3237. a.setfield(val, dtype, offset=0)
  3238. Put a value into a specified place in a field defined by a data-type.
  3239. Place `val` into `a`'s field defined by `dtype` and beginning `offset`
  3240. bytes into the field.
  3241. Parameters
  3242. ----------
  3243. val : object
  3244. Value to be placed in field.
  3245. dtype : dtype object
  3246. Data-type of the field in which to place `val`.
  3247. offset : int, optional
  3248. The number of bytes into the field at which to place `val`.
  3249. Returns
  3250. -------
  3251. None
  3252. See Also
  3253. --------
  3254. getfield
  3255. Examples
  3256. --------
  3257. >>> x = np.eye(3)
  3258. >>> x.getfield(np.float64)
  3259. array([[ 1., 0., 0.],
  3260. [ 0., 1., 0.],
  3261. [ 0., 0., 1.]])
  3262. >>> x.setfield(3, np.int32)
  3263. >>> x.getfield(np.int32)
  3264. array([[3, 3, 3],
  3265. [3, 3, 3],
  3266. [3, 3, 3]])
  3267. >>> x
  3268. array([[ 1.00000000e+000, 1.48219694e-323, 1.48219694e-323],
  3269. [ 1.48219694e-323, 1.00000000e+000, 1.48219694e-323],
  3270. [ 1.48219694e-323, 1.48219694e-323, 1.00000000e+000]])
  3271. >>> x.setfield(np.eye(3), np.int32)
  3272. >>> x
  3273. array([[ 1., 0., 0.],
  3274. [ 0., 1., 0.],
  3275. [ 0., 0., 1.]])
  3276. """))
  3277. add_newdoc('numpy.core.multiarray', 'ndarray', ('setflags',
  3278. """
  3279. a.setflags(write=None, align=None, uic=None)
  3280. Set array flags WRITEABLE, ALIGNED, and UPDATEIFCOPY, respectively.
  3281. These Boolean-valued flags affect how numpy interprets the memory
  3282. area used by `a` (see Notes below). The ALIGNED flag can only
  3283. be set to True if the data is actually aligned according to the type.
  3284. The UPDATEIFCOPY flag can never be set to True. The flag WRITEABLE
  3285. can only be set to True if the array owns its own memory, or the
  3286. ultimate owner of the memory exposes a writeable buffer interface,
  3287. or is a string. (The exception for string is made so that unpickling
  3288. can be done without copying memory.)
  3289. Parameters
  3290. ----------
  3291. write : bool, optional
  3292. Describes whether or not `a` can be written to.
  3293. align : bool, optional
  3294. Describes whether or not `a` is aligned properly for its type.
  3295. uic : bool, optional
  3296. Describes whether or not `a` is a copy of another "base" array.
  3297. Notes
  3298. -----
  3299. Array flags provide information about how the memory area used
  3300. for the array is to be interpreted. There are 6 Boolean flags
  3301. in use, only three of which can be changed by the user:
  3302. UPDATEIFCOPY, WRITEABLE, and ALIGNED.
  3303. WRITEABLE (W) the data area can be written to;
  3304. ALIGNED (A) the data and strides are aligned appropriately for the hardware
  3305. (as determined by the compiler);
  3306. UPDATEIFCOPY (U) this array is a copy of some other array (referenced
  3307. by .base). When this array is deallocated, the base array will be
  3308. updated with the contents of this array.
  3309. All flags can be accessed using their first (upper case) letter as well
  3310. as the full name.
  3311. Examples
  3312. --------
  3313. >>> y
  3314. array([[3, 1, 7],
  3315. [2, 0, 0],
  3316. [8, 5, 9]])
  3317. >>> y.flags
  3318. C_CONTIGUOUS : True
  3319. F_CONTIGUOUS : False
  3320. OWNDATA : True
  3321. WRITEABLE : True
  3322. ALIGNED : True
  3323. UPDATEIFCOPY : False
  3324. >>> y.setflags(write=0, align=0)
  3325. >>> y.flags
  3326. C_CONTIGUOUS : True
  3327. F_CONTIGUOUS : False
  3328. OWNDATA : True
  3329. WRITEABLE : False
  3330. ALIGNED : False
  3331. UPDATEIFCOPY : False
  3332. >>> y.setflags(uic=1)
  3333. Traceback (most recent call last):
  3334. File "<stdin>", line 1, in <module>
  3335. ValueError: cannot set UPDATEIFCOPY flag to True
  3336. """))
  3337. add_newdoc('numpy.core.multiarray', 'ndarray', ('sort',
  3338. """
  3339. a.sort(axis=-1, kind='quicksort', order=None)
  3340. Sort an array, in-place.
  3341. Parameters
  3342. ----------
  3343. axis : int, optional
  3344. Axis along which to sort. Default is -1, which means sort along the
  3345. last axis.
  3346. kind : {'quicksort', 'mergesort', 'heapsort'}, optional
  3347. Sorting algorithm. Default is 'quicksort'.
  3348. order : str or list of str, optional
  3349. When `a` is an array with fields defined, this argument specifies
  3350. which fields to compare first, second, etc. A single field can
  3351. be specified as a string, and not all fields need be specified,
  3352. but unspecified fields will still be used, in the order in which
  3353. they come up in the dtype, to break ties.
  3354. See Also
  3355. --------
  3356. numpy.sort : Return a sorted copy of an array.
  3357. argsort : Indirect sort.
  3358. lexsort : Indirect stable sort on multiple keys.
  3359. searchsorted : Find elements in sorted array.
  3360. partition: Partial sort.
  3361. Notes
  3362. -----
  3363. See ``sort`` for notes on the different sorting algorithms.
  3364. Examples
  3365. --------
  3366. >>> a = np.array([[1,4], [3,1]])
  3367. >>> a.sort(axis=1)
  3368. >>> a
  3369. array([[1, 4],
  3370. [1, 3]])
  3371. >>> a.sort(axis=0)
  3372. >>> a
  3373. array([[1, 3],
  3374. [1, 4]])
  3375. Use the `order` keyword to specify a field to use when sorting a
  3376. structured array:
  3377. >>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)])
  3378. >>> a.sort(order='y')
  3379. >>> a
  3380. array([('c', 1), ('a', 2)],
  3381. dtype=[('x', '|S1'), ('y', '<i4')])
  3382. """))
  3383. add_newdoc('numpy.core.multiarray', 'ndarray', ('partition',
  3384. """
  3385. a.partition(kth, axis=-1, kind='introselect', order=None)
  3386. Rearranges the elements in the array in such a way that value of the
  3387. element in kth position is in the position it would be in a sorted array.
  3388. All elements smaller than the kth element are moved before this element and
  3389. all equal or greater are moved behind it. The ordering of the elements in
  3390. the two partitions is undefined.
  3391. .. versionadded:: 1.8.0
  3392. Parameters
  3393. ----------
  3394. kth : int or sequence of ints
  3395. Element index to partition by. The kth element value will be in its
  3396. final sorted position and all smaller elements will be moved before it
  3397. and all equal or greater elements behind it.
  3398. The order all elements in the partitions is undefined.
  3399. If provided with a sequence of kth it will partition all elements
  3400. indexed by kth of them into their sorted position at once.
  3401. axis : int, optional
  3402. Axis along which to sort. Default is -1, which means sort along the
  3403. last axis.
  3404. kind : {'introselect'}, optional
  3405. Selection algorithm. Default is 'introselect'.
  3406. order : str or list of str, optional
  3407. When `a` is an array with fields defined, this argument specifies
  3408. which fields to compare first, second, etc. A single field can
  3409. be specified as a string, and not all fields need be specified,
  3410. but unspecified fields will still be used, in the order in which
  3411. they come up in the dtype, to break ties.
  3412. See Also
  3413. --------
  3414. numpy.partition : Return a parititioned copy of an array.
  3415. argpartition : Indirect partition.
  3416. sort : Full sort.
  3417. Notes
  3418. -----
  3419. See ``np.partition`` for notes on the different algorithms.
  3420. Examples
  3421. --------
  3422. >>> a = np.array([3, 4, 2, 1])
  3423. >>> a.partition(a, 3)
  3424. >>> a
  3425. array([2, 1, 3, 4])
  3426. >>> a.partition((1, 3))
  3427. array([1, 2, 3, 4])
  3428. """))
  3429. add_newdoc('numpy.core.multiarray', 'ndarray', ('squeeze',
  3430. """
  3431. a.squeeze(axis=None)
  3432. Remove single-dimensional entries from the shape of `a`.
  3433. Refer to `numpy.squeeze` for full documentation.
  3434. See Also
  3435. --------
  3436. numpy.squeeze : equivalent function
  3437. """))
  3438. add_newdoc('numpy.core.multiarray', 'ndarray', ('std',
  3439. """
  3440. a.std(axis=None, dtype=None, out=None, ddof=0, keepdims=False)
  3441. Returns the standard deviation of the array elements along given axis.
  3442. Refer to `numpy.std` for full documentation.
  3443. See Also
  3444. --------
  3445. numpy.std : equivalent function
  3446. """))
  3447. add_newdoc('numpy.core.multiarray', 'ndarray', ('sum',
  3448. """
  3449. a.sum(axis=None, dtype=None, out=None, keepdims=False)
  3450. Return the sum of the array elements over the given axis.
  3451. Refer to `numpy.sum` for full documentation.
  3452. See Also
  3453. --------
  3454. numpy.sum : equivalent function
  3455. """))
  3456. add_newdoc('numpy.core.multiarray', 'ndarray', ('swapaxes',
  3457. """
  3458. a.swapaxes(axis1, axis2)
  3459. Return a view of the array with `axis1` and `axis2` interchanged.
  3460. Refer to `numpy.swapaxes` for full documentation.
  3461. See Also
  3462. --------
  3463. numpy.swapaxes : equivalent function
  3464. """))
  3465. add_newdoc('numpy.core.multiarray', 'ndarray', ('take',
  3466. """
  3467. a.take(indices, axis=None, out=None, mode='raise')
  3468. Return an array formed from the elements of `a` at the given indices.
  3469. Refer to `numpy.take` for full documentation.
  3470. See Also
  3471. --------
  3472. numpy.take : equivalent function
  3473. """))
  3474. add_newdoc('numpy.core.multiarray', 'ndarray', ('tofile',
  3475. """
  3476. a.tofile(fid, sep="", format="%s")
  3477. Write array to a file as text or binary (default).
  3478. Data is always written in 'C' order, independent of the order of `a`.
  3479. The data produced by this method can be recovered using the function
  3480. fromfile().
  3481. Parameters
  3482. ----------
  3483. fid : file or str
  3484. An open file object, or a string containing a filename.
  3485. sep : str
  3486. Separator between array items for text output.
  3487. If "" (empty), a binary file is written, equivalent to
  3488. ``file.write(a.tobytes())``.
  3489. format : str
  3490. Format string for text file output.
  3491. Each entry in the array is formatted to text by first converting
  3492. it to the closest Python type, and then using "format" % item.
  3493. Notes
  3494. -----
  3495. This is a convenience function for quick storage of array data.
  3496. Information on endianness and precision is lost, so this method is not a
  3497. good choice for files intended to archive data or transport data between
  3498. machines with different endianness. Some of these problems can be overcome
  3499. by outputting the data as text files, at the expense of speed and file
  3500. size.
  3501. """))
  3502. add_newdoc('numpy.core.multiarray', 'ndarray', ('tolist',
  3503. """
  3504. a.tolist()
  3505. Return the array as a (possibly nested) list.
  3506. Return a copy of the array data as a (nested) Python list.
  3507. Data items are converted to the nearest compatible Python type.
  3508. Parameters
  3509. ----------
  3510. none
  3511. Returns
  3512. -------
  3513. y : list
  3514. The possibly nested list of array elements.
  3515. Notes
  3516. -----
  3517. The array may be recreated, ``a = np.array(a.tolist())``.
  3518. Examples
  3519. --------
  3520. >>> a = np.array([1, 2])
  3521. >>> a.tolist()
  3522. [1, 2]
  3523. >>> a = np.array([[1, 2], [3, 4]])
  3524. >>> list(a)
  3525. [array([1, 2]), array([3, 4])]
  3526. >>> a.tolist()
  3527. [[1, 2], [3, 4]]
  3528. """))
  3529. tobytesdoc = """
  3530. a.{name}(order='C')
  3531. Construct Python bytes containing the raw data bytes in the array.
  3532. Constructs Python bytes showing a copy of the raw contents of
  3533. data memory. The bytes object can be produced in either 'C' or 'Fortran',
  3534. or 'Any' order (the default is 'C'-order). 'Any' order means C-order
  3535. unless the F_CONTIGUOUS flag in the array is set, in which case it
  3536. means 'Fortran' order.
  3537. {deprecated}
  3538. Parameters
  3539. ----------
  3540. order : {{'C', 'F', None}}, optional
  3541. Order of the data for multidimensional arrays:
  3542. C, Fortran, or the same as for the original array.
  3543. Returns
  3544. -------
  3545. s : bytes
  3546. Python bytes exhibiting a copy of `a`'s raw data.
  3547. Examples
  3548. --------
  3549. >>> x = np.array([[0, 1], [2, 3]])
  3550. >>> x.tobytes()
  3551. b'\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x03\\x00\\x00\\x00'
  3552. >>> x.tobytes('C') == x.tobytes()
  3553. True
  3554. >>> x.tobytes('F')
  3555. b'\\x00\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x03\\x00\\x00\\x00'
  3556. """
  3557. add_newdoc('numpy.core.multiarray', 'ndarray',
  3558. ('tostring', tobytesdoc.format(name='tostring',
  3559. deprecated=
  3560. 'This function is a compatibility '
  3561. 'alias for tobytes. Despite its '
  3562. 'name it returns bytes not '
  3563. 'strings.')))
  3564. add_newdoc('numpy.core.multiarray', 'ndarray',
  3565. ('tobytes', tobytesdoc.format(name='tobytes',
  3566. deprecated='.. versionadded:: 1.9.0')))
  3567. add_newdoc('numpy.core.multiarray', 'ndarray', ('trace',
  3568. """
  3569. a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None)
  3570. Return the sum along diagonals of the array.
  3571. Refer to `numpy.trace` for full documentation.
  3572. See Also
  3573. --------
  3574. numpy.trace : equivalent function
  3575. """))
  3576. add_newdoc('numpy.core.multiarray', 'ndarray', ('transpose',
  3577. """
  3578. a.transpose(*axes)
  3579. Returns a view of the array with axes transposed.
  3580. For a 1-D array, this has no effect. (To change between column and
  3581. row vectors, first cast the 1-D array into a matrix object.)
  3582. For a 2-D array, this is the usual matrix transpose.
  3583. For an n-D array, if axes are given, their order indicates how the
  3584. axes are permuted (see Examples). If axes are not provided and
  3585. ``a.shape = (i[0], i[1], ... i[n-2], i[n-1])``, then
  3586. ``a.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0])``.
  3587. Parameters
  3588. ----------
  3589. axes : None, tuple of ints, or `n` ints
  3590. * None or no argument: reverses the order of the axes.
  3591. * tuple of ints: `i` in the `j`-th place in the tuple means `a`'s
  3592. `i`-th axis becomes `a.transpose()`'s `j`-th axis.
  3593. * `n` ints: same as an n-tuple of the same ints (this form is
  3594. intended simply as a "convenience" alternative to the tuple form)
  3595. Returns
  3596. -------
  3597. out : ndarray
  3598. View of `a`, with axes suitably permuted.
  3599. See Also
  3600. --------
  3601. ndarray.T : Array property returning the array transposed.
  3602. Examples
  3603. --------
  3604. >>> a = np.array([[1, 2], [3, 4]])
  3605. >>> a
  3606. array([[1, 2],
  3607. [3, 4]])
  3608. >>> a.transpose()
  3609. array([[1, 3],
  3610. [2, 4]])
  3611. >>> a.transpose((1, 0))
  3612. array([[1, 3],
  3613. [2, 4]])
  3614. >>> a.transpose(1, 0)
  3615. array([[1, 3],
  3616. [2, 4]])
  3617. """))
  3618. add_newdoc('numpy.core.multiarray', 'ndarray', ('var',
  3619. """
  3620. a.var(axis=None, dtype=None, out=None, ddof=0, keepdims=False)
  3621. Returns the variance of the array elements, along given axis.
  3622. Refer to `numpy.var` for full documentation.
  3623. See Also
  3624. --------
  3625. numpy.var : equivalent function
  3626. """))
  3627. add_newdoc('numpy.core.multiarray', 'ndarray', ('view',
  3628. """
  3629. a.view(dtype=None, type=None)
  3630. New view of array with the same data.
  3631. Parameters
  3632. ----------
  3633. dtype : data-type or ndarray sub-class, optional
  3634. Data-type descriptor of the returned view, e.g., float32 or int16. The
  3635. default, None, results in the view having the same data-type as `a`.
  3636. This argument can also be specified as an ndarray sub-class, which
  3637. then specifies the type of the returned object (this is equivalent to
  3638. setting the ``type`` parameter).
  3639. type : Python type, optional
  3640. Type of the returned view, e.g., ndarray or matrix. Again, the
  3641. default None results in type preservation.
  3642. Notes
  3643. -----
  3644. ``a.view()`` is used two different ways:
  3645. ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view
  3646. of the array's memory with a different data-type. This can cause a
  3647. reinterpretation of the bytes of memory.
  3648. ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just
  3649. returns an instance of `ndarray_subclass` that looks at the same array
  3650. (same shape, dtype, etc.) This does not cause a reinterpretation of the
  3651. memory.
  3652. For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of
  3653. bytes per entry than the previous dtype (for example, converting a
  3654. regular array to a structured array), then the behavior of the view
  3655. cannot be predicted just from the superficial appearance of ``a`` (shown
  3656. by ``print(a)``). It also depends on exactly how ``a`` is stored in
  3657. memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus
  3658. defined as a slice or transpose, etc., the view may give different
  3659. results.
  3660. Examples
  3661. --------
  3662. >>> x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)])
  3663. Viewing array data using a different type and dtype:
  3664. >>> y = x.view(dtype=np.int16, type=np.matrix)
  3665. >>> y
  3666. matrix([[513]], dtype=int16)
  3667. >>> print(type(y))
  3668. <class 'numpy.matrixlib.defmatrix.matrix'>
  3669. Creating a view on a structured array so it can be used in calculations
  3670. >>> x = np.array([(1, 2),(3,4)], dtype=[('a', np.int8), ('b', np.int8)])
  3671. >>> xv = x.view(dtype=np.int8).reshape(-1,2)
  3672. >>> xv
  3673. array([[1, 2],
  3674. [3, 4]], dtype=int8)
  3675. >>> xv.mean(0)
  3676. array([ 2., 3.])
  3677. Making changes to the view changes the underlying array
  3678. >>> xv[0,1] = 20
  3679. >>> print(x)
  3680. [(1, 20) (3, 4)]
  3681. Using a view to convert an array to a recarray:
  3682. >>> z = x.view(np.recarray)
  3683. >>> z.a
  3684. array([1], dtype=int8)
  3685. Views share data:
  3686. >>> x[0] = (9, 10)
  3687. >>> z[0]
  3688. (9, 10)
  3689. Views that change the dtype size (bytes per entry) should normally be
  3690. avoided on arrays defined by slices, transposes, fortran-ordering, etc.:
  3691. >>> x = np.array([[1,2,3],[4,5,6]], dtype=np.int16)
  3692. >>> y = x[:, 0:2]
  3693. >>> y
  3694. array([[1, 2],
  3695. [4, 5]], dtype=int16)
  3696. >>> y.view(dtype=[('width', np.int16), ('length', np.int16)])
  3697. Traceback (most recent call last):
  3698. File "<stdin>", line 1, in <module>
  3699. ValueError: new type not compatible with array.
  3700. >>> z = y.copy()
  3701. >>> z.view(dtype=[('width', np.int16), ('length', np.int16)])
  3702. array([[(1, 2)],
  3703. [(4, 5)]], dtype=[('width', '<i2'), ('length', '<i2')])
  3704. """))
  3705. ##############################################################################
  3706. #
  3707. # umath functions
  3708. #
  3709. ##############################################################################
  3710. add_newdoc('numpy.core.umath', 'frompyfunc',
  3711. """
  3712. frompyfunc(func, nin, nout)
  3713. Takes an arbitrary Python function and returns a Numpy ufunc.
  3714. Can be used, for example, to add broadcasting to a built-in Python
  3715. function (see Examples section).
  3716. Parameters
  3717. ----------
  3718. func : Python function object
  3719. An arbitrary Python function.
  3720. nin : int
  3721. The number of input arguments.
  3722. nout : int
  3723. The number of objects returned by `func`.
  3724. Returns
  3725. -------
  3726. out : ufunc
  3727. Returns a Numpy universal function (``ufunc``) object.
  3728. Notes
  3729. -----
  3730. The returned ufunc always returns PyObject arrays.
  3731. Examples
  3732. --------
  3733. Use frompyfunc to add broadcasting to the Python function ``oct``:
  3734. >>> oct_array = np.frompyfunc(oct, 1, 1)
  3735. >>> oct_array(np.array((10, 30, 100)))
  3736. array([012, 036, 0144], dtype=object)
  3737. >>> np.array((oct(10), oct(30), oct(100))) # for comparison
  3738. array(['012', '036', '0144'],
  3739. dtype='|S4')
  3740. """)
  3741. add_newdoc('numpy.core.umath', 'geterrobj',
  3742. """
  3743. geterrobj()
  3744. Return the current object that defines floating-point error handling.
  3745. The error object contains all information that defines the error handling
  3746. behavior in Numpy. `geterrobj` is used internally by the other
  3747. functions that get and set error handling behavior (`geterr`, `seterr`,
  3748. `geterrcall`, `seterrcall`).
  3749. Returns
  3750. -------
  3751. errobj : list
  3752. The error object, a list containing three elements:
  3753. [internal numpy buffer size, error mask, error callback function].
  3754. The error mask is a single integer that holds the treatment information
  3755. on all four floating point errors. The information for each error type
  3756. is contained in three bits of the integer. If we print it in base 8, we
  3757. can see what treatment is set for "invalid", "under", "over", and
  3758. "divide" (in that order). The printed string can be interpreted with
  3759. * 0 : 'ignore'
  3760. * 1 : 'warn'
  3761. * 2 : 'raise'
  3762. * 3 : 'call'
  3763. * 4 : 'print'
  3764. * 5 : 'log'
  3765. See Also
  3766. --------
  3767. seterrobj, seterr, geterr, seterrcall, geterrcall
  3768. getbufsize, setbufsize
  3769. Notes
  3770. -----
  3771. For complete documentation of the types of floating-point exceptions and
  3772. treatment options, see `seterr`.
  3773. Examples
  3774. --------
  3775. >>> np.geterrobj() # first get the defaults
  3776. [10000, 0, None]
  3777. >>> def err_handler(type, flag):
  3778. ... print("Floating point error (%s), with flag %s" % (type, flag))
  3779. ...
  3780. >>> old_bufsize = np.setbufsize(20000)
  3781. >>> old_err = np.seterr(divide='raise')
  3782. >>> old_handler = np.seterrcall(err_handler)
  3783. >>> np.geterrobj()
  3784. [20000, 2, <function err_handler at 0x91dcaac>]
  3785. >>> old_err = np.seterr(all='ignore')
  3786. >>> np.base_repr(np.geterrobj()[1], 8)
  3787. '0'
  3788. >>> old_err = np.seterr(divide='warn', over='log', under='call',
  3789. invalid='print')
  3790. >>> np.base_repr(np.geterrobj()[1], 8)
  3791. '4351'
  3792. """)
  3793. add_newdoc('numpy.core.umath', 'seterrobj',
  3794. """
  3795. seterrobj(errobj)
  3796. Set the object that defines floating-point error handling.
  3797. The error object contains all information that defines the error handling
  3798. behavior in Numpy. `seterrobj` is used internally by the other
  3799. functions that set error handling behavior (`seterr`, `seterrcall`).
  3800. Parameters
  3801. ----------
  3802. errobj : list
  3803. The error object, a list containing three elements:
  3804. [internal numpy buffer size, error mask, error callback function].
  3805. The error mask is a single integer that holds the treatment information
  3806. on all four floating point errors. The information for each error type
  3807. is contained in three bits of the integer. If we print it in base 8, we
  3808. can see what treatment is set for "invalid", "under", "over", and
  3809. "divide" (in that order). The printed string can be interpreted with
  3810. * 0 : 'ignore'
  3811. * 1 : 'warn'
  3812. * 2 : 'raise'
  3813. * 3 : 'call'
  3814. * 4 : 'print'
  3815. * 5 : 'log'
  3816. See Also
  3817. --------
  3818. geterrobj, seterr, geterr, seterrcall, geterrcall
  3819. getbufsize, setbufsize
  3820. Notes
  3821. -----
  3822. For complete documentation of the types of floating-point exceptions and
  3823. treatment options, see `seterr`.
  3824. Examples
  3825. --------
  3826. >>> old_errobj = np.geterrobj() # first get the defaults
  3827. >>> old_errobj
  3828. [10000, 0, None]
  3829. >>> def err_handler(type, flag):
  3830. ... print("Floating point error (%s), with flag %s" % (type, flag))
  3831. ...
  3832. >>> new_errobj = [20000, 12, err_handler]
  3833. >>> np.seterrobj(new_errobj)
  3834. >>> np.base_repr(12, 8) # int for divide=4 ('print') and over=1 ('warn')
  3835. '14'
  3836. >>> np.geterr()
  3837. {'over': 'warn', 'divide': 'print', 'invalid': 'ignore', 'under': 'ignore'}
  3838. >>> np.geterrcall() is err_handler
  3839. True
  3840. """)
  3841. ##############################################################################
  3842. #
  3843. # compiled_base functions
  3844. #
  3845. ##############################################################################
  3846. add_newdoc('numpy.core.multiarray', 'digitize',
  3847. """
  3848. digitize(x, bins, right=False)
  3849. Return the indices of the bins to which each value in input array belongs.
  3850. Each index ``i`` returned is such that ``bins[i-1] <= x < bins[i]`` if
  3851. `bins` is monotonically increasing, or ``bins[i-1] > x >= bins[i]`` if
  3852. `bins` is monotonically decreasing. If values in `x` are beyond the
  3853. bounds of `bins`, 0 or ``len(bins)`` is returned as appropriate. If right
  3854. is True, then the right bin is closed so that the index ``i`` is such
  3855. that ``bins[i-1] < x <= bins[i]`` or bins[i-1] >= x > bins[i]`` if `bins`
  3856. is monotonically increasing or decreasing, respectively.
  3857. Parameters
  3858. ----------
  3859. x : array_like
  3860. Input array to be binned. Prior to Numpy 1.10.0, this array had to
  3861. be 1-dimensional, but can now have any shape.
  3862. bins : array_like
  3863. Array of bins. It has to be 1-dimensional and monotonic.
  3864. right : bool, optional
  3865. Indicating whether the intervals include the right or the left bin
  3866. edge. Default behavior is (right==False) indicating that the interval
  3867. does not include the right edge. The left bin end is open in this
  3868. case, i.e., bins[i-1] <= x < bins[i] is the default behavior for
  3869. monotonically increasing bins.
  3870. Returns
  3871. -------
  3872. out : ndarray of ints
  3873. Output array of indices, of same shape as `x`.
  3874. Raises
  3875. ------
  3876. ValueError
  3877. If `bins` is not monotonic.
  3878. TypeError
  3879. If the type of the input is complex.
  3880. See Also
  3881. --------
  3882. bincount, histogram, unique
  3883. Notes
  3884. -----
  3885. If values in `x` are such that they fall outside the bin range,
  3886. attempting to index `bins` with the indices that `digitize` returns
  3887. will result in an IndexError.
  3888. .. versionadded:: 1.10.0
  3889. `np.digitize` is implemented in terms of `np.searchsorted`. This means
  3890. that a binary search is used to bin the values, which scales much better
  3891. for larger number of bins than the previous linear search. It also removes
  3892. the requirement for the input array to be 1-dimensional.
  3893. Examples
  3894. --------
  3895. >>> x = np.array([0.2, 6.4, 3.0, 1.6])
  3896. >>> bins = np.array([0.0, 1.0, 2.5, 4.0, 10.0])
  3897. >>> inds = np.digitize(x, bins)
  3898. >>> inds
  3899. array([1, 4, 3, 2])
  3900. >>> for n in range(x.size):
  3901. ... print(bins[inds[n]-1], "<=", x[n], "<", bins[inds[n]])
  3902. ...
  3903. 0.0 <= 0.2 < 1.0
  3904. 4.0 <= 6.4 < 10.0
  3905. 2.5 <= 3.0 < 4.0
  3906. 1.0 <= 1.6 < 2.5
  3907. >>> x = np.array([1.2, 10.0, 12.4, 15.5, 20.])
  3908. >>> bins = np.array([0, 5, 10, 15, 20])
  3909. >>> np.digitize(x,bins,right=True)
  3910. array([1, 2, 3, 4, 4])
  3911. >>> np.digitize(x,bins,right=False)
  3912. array([1, 3, 3, 4, 5])
  3913. """)
  3914. add_newdoc('numpy.core.multiarray', 'bincount',
  3915. """
  3916. bincount(x, weights=None, minlength=None)
  3917. Count number of occurrences of each value in array of non-negative ints.
  3918. The number of bins (of size 1) is one larger than the largest value in
  3919. `x`. If `minlength` is specified, there will be at least this number
  3920. of bins in the output array (though it will be longer if necessary,
  3921. depending on the contents of `x`).
  3922. Each bin gives the number of occurrences of its index value in `x`.
  3923. If `weights` is specified the input array is weighted by it, i.e. if a
  3924. value ``n`` is found at position ``i``, ``out[n] += weight[i]`` instead
  3925. of ``out[n] += 1``.
  3926. Parameters
  3927. ----------
  3928. x : array_like, 1 dimension, nonnegative ints
  3929. Input array.
  3930. weights : array_like, optional
  3931. Weights, array of the same shape as `x`.
  3932. minlength : int, optional
  3933. A minimum number of bins for the output array.
  3934. .. versionadded:: 1.6.0
  3935. Returns
  3936. -------
  3937. out : ndarray of ints
  3938. The result of binning the input array.
  3939. The length of `out` is equal to ``np.amax(x)+1``.
  3940. Raises
  3941. ------
  3942. ValueError
  3943. If the input is not 1-dimensional, or contains elements with negative
  3944. values, or if `minlength` is non-positive.
  3945. TypeError
  3946. If the type of the input is float or complex.
  3947. See Also
  3948. --------
  3949. histogram, digitize, unique
  3950. Examples
  3951. --------
  3952. >>> np.bincount(np.arange(5))
  3953. array([1, 1, 1, 1, 1])
  3954. >>> np.bincount(np.array([0, 1, 1, 3, 2, 1, 7]))
  3955. array([1, 3, 1, 1, 0, 0, 0, 1])
  3956. >>> x = np.array([0, 1, 1, 3, 2, 1, 7, 23])
  3957. >>> np.bincount(x).size == np.amax(x)+1
  3958. True
  3959. The input array needs to be of integer dtype, otherwise a
  3960. TypeError is raised:
  3961. >>> np.bincount(np.arange(5, dtype=np.float))
  3962. Traceback (most recent call last):
  3963. File "<stdin>", line 1, in <module>
  3964. TypeError: array cannot be safely cast to required type
  3965. A possible use of ``bincount`` is to perform sums over
  3966. variable-size chunks of an array, using the ``weights`` keyword.
  3967. >>> w = np.array([0.3, 0.5, 0.2, 0.7, 1., -0.6]) # weights
  3968. >>> x = np.array([0, 1, 1, 2, 2, 2])
  3969. >>> np.bincount(x, weights=w)
  3970. array([ 0.3, 0.7, 1.1])
  3971. """)
  3972. add_newdoc('numpy.core.multiarray', 'ravel_multi_index',
  3973. """
  3974. ravel_multi_index(multi_index, dims, mode='raise', order='C')
  3975. Converts a tuple of index arrays into an array of flat
  3976. indices, applying boundary modes to the multi-index.
  3977. Parameters
  3978. ----------
  3979. multi_index : tuple of array_like
  3980. A tuple of integer arrays, one array for each dimension.
  3981. dims : tuple of ints
  3982. The shape of array into which the indices from ``multi_index`` apply.
  3983. mode : {'raise', 'wrap', 'clip'}, optional
  3984. Specifies how out-of-bounds indices are handled. Can specify
  3985. either one mode or a tuple of modes, one mode per index.
  3986. * 'raise' -- raise an error (default)
  3987. * 'wrap' -- wrap around
  3988. * 'clip' -- clip to the range
  3989. In 'clip' mode, a negative index which would normally
  3990. wrap will clip to 0 instead.
  3991. order : {'C', 'F'}, optional
  3992. Determines whether the multi-index should be viewed as
  3993. indexing in row-major (C-style) or column-major
  3994. (Fortran-style) order.
  3995. Returns
  3996. -------
  3997. raveled_indices : ndarray
  3998. An array of indices into the flattened version of an array
  3999. of dimensions ``dims``.
  4000. See Also
  4001. --------
  4002. unravel_index
  4003. Notes
  4004. -----
  4005. .. versionadded:: 1.6.0
  4006. Examples
  4007. --------
  4008. >>> arr = np.array([[3,6,6],[4,5,1]])
  4009. >>> np.ravel_multi_index(arr, (7,6))
  4010. array([22, 41, 37])
  4011. >>> np.ravel_multi_index(arr, (7,6), order='F')
  4012. array([31, 41, 13])
  4013. >>> np.ravel_multi_index(arr, (4,6), mode='clip')
  4014. array([22, 23, 19])
  4015. >>> np.ravel_multi_index(arr, (4,4), mode=('clip','wrap'))
  4016. array([12, 13, 13])
  4017. >>> np.ravel_multi_index((3,1,4,1), (6,7,8,9))
  4018. 1621
  4019. """)
  4020. add_newdoc('numpy.core.multiarray', 'unravel_index',
  4021. """
  4022. unravel_index(indices, dims, order='C')
  4023. Converts a flat index or array of flat indices into a tuple
  4024. of coordinate arrays.
  4025. Parameters
  4026. ----------
  4027. indices : array_like
  4028. An integer array whose elements are indices into the flattened
  4029. version of an array of dimensions ``dims``. Before version 1.6.0,
  4030. this function accepted just one index value.
  4031. dims : tuple of ints
  4032. The shape of the array to use for unraveling ``indices``.
  4033. order : {'C', 'F'}, optional
  4034. Determines whether the indices should be viewed as indexing in
  4035. row-major (C-style) or column-major (Fortran-style) order.
  4036. .. versionadded:: 1.6.0
  4037. Returns
  4038. -------
  4039. unraveled_coords : tuple of ndarray
  4040. Each array in the tuple has the same shape as the ``indices``
  4041. array.
  4042. See Also
  4043. --------
  4044. ravel_multi_index
  4045. Examples
  4046. --------
  4047. >>> np.unravel_index([22, 41, 37], (7,6))
  4048. (array([3, 6, 6]), array([4, 5, 1]))
  4049. >>> np.unravel_index([31, 41, 13], (7,6), order='F')
  4050. (array([3, 6, 6]), array([4, 5, 1]))
  4051. >>> np.unravel_index(1621, (6,7,8,9))
  4052. (3, 1, 4, 1)
  4053. """)
  4054. add_newdoc('numpy.core.multiarray', 'add_docstring',
  4055. """
  4056. add_docstring(obj, docstring)
  4057. Add a docstring to a built-in obj if possible.
  4058. If the obj already has a docstring raise a RuntimeError
  4059. If this routine does not know how to add a docstring to the object
  4060. raise a TypeError
  4061. """)
  4062. add_newdoc('numpy.core.umath', '_add_newdoc_ufunc',
  4063. """
  4064. add_ufunc_docstring(ufunc, new_docstring)
  4065. Replace the docstring for a ufunc with new_docstring.
  4066. This method will only work if the current docstring for
  4067. the ufunc is NULL. (At the C level, i.e. when ufunc->doc is NULL.)
  4068. Parameters
  4069. ----------
  4070. ufunc : numpy.ufunc
  4071. A ufunc whose current doc is NULL.
  4072. new_docstring : string
  4073. The new docstring for the ufunc.
  4074. Notes
  4075. -----
  4076. This method allocates memory for new_docstring on
  4077. the heap. Technically this creates a mempory leak, since this
  4078. memory will not be reclaimed until the end of the program
  4079. even if the ufunc itself is removed. However this will only
  4080. be a problem if the user is repeatedly creating ufuncs with
  4081. no documentation, adding documentation via add_newdoc_ufunc,
  4082. and then throwing away the ufunc.
  4083. """)
  4084. add_newdoc('numpy.core.multiarray', 'packbits',
  4085. """
  4086. packbits(myarray, axis=None)
  4087. Packs the elements of a binary-valued array into bits in a uint8 array.
  4088. The result is padded to full bytes by inserting zero bits at the end.
  4089. Parameters
  4090. ----------
  4091. myarray : array_like
  4092. An integer type array whose elements should be packed to bits.
  4093. axis : int, optional
  4094. The dimension over which bit-packing is done.
  4095. ``None`` implies packing the flattened array.
  4096. Returns
  4097. -------
  4098. packed : ndarray
  4099. Array of type uint8 whose elements represent bits corresponding to the
  4100. logical (0 or nonzero) value of the input elements. The shape of
  4101. `packed` has the same number of dimensions as the input (unless `axis`
  4102. is None, in which case the output is 1-D).
  4103. See Also
  4104. --------
  4105. unpackbits: Unpacks elements of a uint8 array into a binary-valued output
  4106. array.
  4107. Examples
  4108. --------
  4109. >>> a = np.array([[[1,0,1],
  4110. ... [0,1,0]],
  4111. ... [[1,1,0],
  4112. ... [0,0,1]]])
  4113. >>> b = np.packbits(a, axis=-1)
  4114. >>> b
  4115. array([[[160],[64]],[[192],[32]]], dtype=uint8)
  4116. Note that in binary 160 = 1010 0000, 64 = 0100 0000, 192 = 1100 0000,
  4117. and 32 = 0010 0000.
  4118. """)
  4119. add_newdoc('numpy.core.multiarray', 'unpackbits',
  4120. """
  4121. unpackbits(myarray, axis=None)
  4122. Unpacks elements of a uint8 array into a binary-valued output array.
  4123. Each element of `myarray` represents a bit-field that should be unpacked
  4124. into a binary-valued output array. The shape of the output array is either
  4125. 1-D (if `axis` is None) or the same shape as the input array with unpacking
  4126. done along the axis specified.
  4127. Parameters
  4128. ----------
  4129. myarray : ndarray, uint8 type
  4130. Input array.
  4131. axis : int, optional
  4132. Unpacks along this axis.
  4133. Returns
  4134. -------
  4135. unpacked : ndarray, uint8 type
  4136. The elements are binary-valued (0 or 1).
  4137. See Also
  4138. --------
  4139. packbits : Packs the elements of a binary-valued array into bits in a uint8
  4140. array.
  4141. Examples
  4142. --------
  4143. >>> a = np.array([[2], [7], [23]], dtype=np.uint8)
  4144. >>> a
  4145. array([[ 2],
  4146. [ 7],
  4147. [23]], dtype=uint8)
  4148. >>> b = np.unpackbits(a, axis=1)
  4149. >>> b
  4150. array([[0, 0, 0, 0, 0, 0, 1, 0],
  4151. [0, 0, 0, 0, 0, 1, 1, 1],
  4152. [0, 0, 0, 1, 0, 1, 1, 1]], dtype=uint8)
  4153. """)
  4154. ##############################################################################
  4155. #
  4156. # Documentation for ufunc attributes and methods
  4157. #
  4158. ##############################################################################
  4159. ##############################################################################
  4160. #
  4161. # ufunc object
  4162. #
  4163. ##############################################################################
  4164. add_newdoc('numpy.core', 'ufunc',
  4165. """
  4166. Functions that operate element by element on whole arrays.
  4167. To see the documentation for a specific ufunc, use np.info(). For
  4168. example, np.info(np.sin). Because ufuncs are written in C
  4169. (for speed) and linked into Python with NumPy's ufunc facility,
  4170. Python's help() function finds this page whenever help() is called
  4171. on a ufunc.
  4172. A detailed explanation of ufuncs can be found in the "ufuncs.rst"
  4173. file in the NumPy reference guide.
  4174. Unary ufuncs:
  4175. =============
  4176. op(X, out=None)
  4177. Apply op to X elementwise
  4178. Parameters
  4179. ----------
  4180. X : array_like
  4181. Input array.
  4182. out : array_like
  4183. An array to store the output. Must be the same shape as `X`.
  4184. Returns
  4185. -------
  4186. r : array_like
  4187. `r` will have the same shape as `X`; if out is provided, `r`
  4188. will be equal to out.
  4189. Binary ufuncs:
  4190. ==============
  4191. op(X, Y, out=None)
  4192. Apply `op` to `X` and `Y` elementwise. May "broadcast" to make
  4193. the shapes of `X` and `Y` congruent.
  4194. The broadcasting rules are:
  4195. * Dimensions of length 1 may be prepended to either array.
  4196. * Arrays may be repeated along dimensions of length 1.
  4197. Parameters
  4198. ----------
  4199. X : array_like
  4200. First input array.
  4201. Y : array_like
  4202. Second input array.
  4203. out : array_like
  4204. An array to store the output. Must be the same shape as the
  4205. output would have.
  4206. Returns
  4207. -------
  4208. r : array_like
  4209. The return value; if out is provided, `r` will be equal to out.
  4210. """)
  4211. ##############################################################################
  4212. #
  4213. # ufunc attributes
  4214. #
  4215. ##############################################################################
  4216. add_newdoc('numpy.core', 'ufunc', ('identity',
  4217. """
  4218. The identity value.
  4219. Data attribute containing the identity element for the ufunc, if it has one.
  4220. If it does not, the attribute value is None.
  4221. Examples
  4222. --------
  4223. >>> np.add.identity
  4224. 0
  4225. >>> np.multiply.identity
  4226. 1
  4227. >>> np.power.identity
  4228. 1
  4229. >>> print(np.exp.identity)
  4230. None
  4231. """))
  4232. add_newdoc('numpy.core', 'ufunc', ('nargs',
  4233. """
  4234. The number of arguments.
  4235. Data attribute containing the number of arguments the ufunc takes, including
  4236. optional ones.
  4237. Notes
  4238. -----
  4239. Typically this value will be one more than what you might expect because all
  4240. ufuncs take the optional "out" argument.
  4241. Examples
  4242. --------
  4243. >>> np.add.nargs
  4244. 3
  4245. >>> np.multiply.nargs
  4246. 3
  4247. >>> np.power.nargs
  4248. 3
  4249. >>> np.exp.nargs
  4250. 2
  4251. """))
  4252. add_newdoc('numpy.core', 'ufunc', ('nin',
  4253. """
  4254. The number of inputs.
  4255. Data attribute containing the number of arguments the ufunc treats as input.
  4256. Examples
  4257. --------
  4258. >>> np.add.nin
  4259. 2
  4260. >>> np.multiply.nin
  4261. 2
  4262. >>> np.power.nin
  4263. 2
  4264. >>> np.exp.nin
  4265. 1
  4266. """))
  4267. add_newdoc('numpy.core', 'ufunc', ('nout',
  4268. """
  4269. The number of outputs.
  4270. Data attribute containing the number of arguments the ufunc treats as output.
  4271. Notes
  4272. -----
  4273. Since all ufuncs can take output arguments, this will always be (at least) 1.
  4274. Examples
  4275. --------
  4276. >>> np.add.nout
  4277. 1
  4278. >>> np.multiply.nout
  4279. 1
  4280. >>> np.power.nout
  4281. 1
  4282. >>> np.exp.nout
  4283. 1
  4284. """))
  4285. add_newdoc('numpy.core', 'ufunc', ('ntypes',
  4286. """
  4287. The number of types.
  4288. The number of numerical NumPy types - of which there are 18 total - on which
  4289. the ufunc can operate.
  4290. See Also
  4291. --------
  4292. numpy.ufunc.types
  4293. Examples
  4294. --------
  4295. >>> np.add.ntypes
  4296. 18
  4297. >>> np.multiply.ntypes
  4298. 18
  4299. >>> np.power.ntypes
  4300. 17
  4301. >>> np.exp.ntypes
  4302. 7
  4303. >>> np.remainder.ntypes
  4304. 14
  4305. """))
  4306. add_newdoc('numpy.core', 'ufunc', ('types',
  4307. """
  4308. Returns a list with types grouped input->output.
  4309. Data attribute listing the data-type "Domain-Range" groupings the ufunc can
  4310. deliver. The data-types are given using the character codes.
  4311. See Also
  4312. --------
  4313. numpy.ufunc.ntypes
  4314. Examples
  4315. --------
  4316. >>> np.add.types
  4317. ['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l',
  4318. 'LL->L', 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D',
  4319. 'GG->G', 'OO->O']
  4320. >>> np.multiply.types
  4321. ['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l',
  4322. 'LL->L', 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D',
  4323. 'GG->G', 'OO->O']
  4324. >>> np.power.types
  4325. ['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', 'LL->L',
  4326. 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D', 'GG->G',
  4327. 'OO->O']
  4328. >>> np.exp.types
  4329. ['f->f', 'd->d', 'g->g', 'F->F', 'D->D', 'G->G', 'O->O']
  4330. >>> np.remainder.types
  4331. ['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', 'LL->L',
  4332. 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'OO->O']
  4333. """))
  4334. ##############################################################################
  4335. #
  4336. # ufunc methods
  4337. #
  4338. ##############################################################################
  4339. add_newdoc('numpy.core', 'ufunc', ('reduce',
  4340. """
  4341. reduce(a, axis=0, dtype=None, out=None, keepdims=False)
  4342. Reduces `a`'s dimension by one, by applying ufunc along one axis.
  4343. Let :math:`a.shape = (N_0, ..., N_i, ..., N_{M-1})`. Then
  4344. :math:`ufunc.reduce(a, axis=i)[k_0, ..,k_{i-1}, k_{i+1}, .., k_{M-1}]` =
  4345. the result of iterating `j` over :math:`range(N_i)`, cumulatively applying
  4346. ufunc to each :math:`a[k_0, ..,k_{i-1}, j, k_{i+1}, .., k_{M-1}]`.
  4347. For a one-dimensional array, reduce produces results equivalent to:
  4348. ::
  4349. r = op.identity # op = ufunc
  4350. for i in range(len(A)):
  4351. r = op(r, A[i])
  4352. return r
  4353. For example, add.reduce() is equivalent to sum().
  4354. Parameters
  4355. ----------
  4356. a : array_like
  4357. The array to act on.
  4358. axis : None or int or tuple of ints, optional
  4359. Axis or axes along which a reduction is performed.
  4360. The default (`axis` = 0) is perform a reduction over the first
  4361. dimension of the input array. `axis` may be negative, in
  4362. which case it counts from the last to the first axis.
  4363. .. versionadded:: 1.7.0
  4364. If this is `None`, a reduction is performed over all the axes.
  4365. If this is a tuple of ints, a reduction is performed on multiple
  4366. axes, instead of a single axis or all the axes as before.
  4367. For operations which are either not commutative or not associative,
  4368. doing a reduction over multiple axes is not well-defined. The
  4369. ufuncs do not currently raise an exception in this case, but will
  4370. likely do so in the future.
  4371. dtype : data-type code, optional
  4372. The type used to represent the intermediate results. Defaults
  4373. to the data-type of the output array if this is provided, or
  4374. the data-type of the input array if no output array is provided.
  4375. out : ndarray, optional
  4376. A location into which the result is stored. If not provided, a
  4377. freshly-allocated array is returned.
  4378. keepdims : bool, optional
  4379. If this is set to True, the axes which are reduced are left
  4380. in the result as dimensions with size one. With this option,
  4381. the result will broadcast correctly against the original `arr`.
  4382. .. versionadded:: 1.7.0
  4383. Returns
  4384. -------
  4385. r : ndarray
  4386. The reduced array. If `out` was supplied, `r` is a reference to it.
  4387. Examples
  4388. --------
  4389. >>> np.multiply.reduce([2,3,5])
  4390. 30
  4391. A multi-dimensional array example:
  4392. >>> X = np.arange(8).reshape((2,2,2))
  4393. >>> X
  4394. array([[[0, 1],
  4395. [2, 3]],
  4396. [[4, 5],
  4397. [6, 7]]])
  4398. >>> np.add.reduce(X, 0)
  4399. array([[ 4, 6],
  4400. [ 8, 10]])
  4401. >>> np.add.reduce(X) # confirm: default axis value is 0
  4402. array([[ 4, 6],
  4403. [ 8, 10]])
  4404. >>> np.add.reduce(X, 1)
  4405. array([[ 2, 4],
  4406. [10, 12]])
  4407. >>> np.add.reduce(X, 2)
  4408. array([[ 1, 5],
  4409. [ 9, 13]])
  4410. """))
  4411. add_newdoc('numpy.core', 'ufunc', ('accumulate',
  4412. """
  4413. accumulate(array, axis=0, dtype=None, out=None)
  4414. Accumulate the result of applying the operator to all elements.
  4415. For a one-dimensional array, accumulate produces results equivalent to::
  4416. r = np.empty(len(A))
  4417. t = op.identity # op = the ufunc being applied to A's elements
  4418. for i in range(len(A)):
  4419. t = op(t, A[i])
  4420. r[i] = t
  4421. return r
  4422. For example, add.accumulate() is equivalent to np.cumsum().
  4423. For a multi-dimensional array, accumulate is applied along only one
  4424. axis (axis zero by default; see Examples below) so repeated use is
  4425. necessary if one wants to accumulate over multiple axes.
  4426. Parameters
  4427. ----------
  4428. array : array_like
  4429. The array to act on.
  4430. axis : int, optional
  4431. The axis along which to apply the accumulation; default is zero.
  4432. dtype : data-type code, optional
  4433. The data-type used to represent the intermediate results. Defaults
  4434. to the data-type of the output array if such is provided, or the
  4435. the data-type of the input array if no output array is provided.
  4436. out : ndarray, optional
  4437. A location into which the result is stored. If not provided a
  4438. freshly-allocated array is returned.
  4439. Returns
  4440. -------
  4441. r : ndarray
  4442. The accumulated values. If `out` was supplied, `r` is a reference to
  4443. `out`.
  4444. Examples
  4445. --------
  4446. 1-D array examples:
  4447. >>> np.add.accumulate([2, 3, 5])
  4448. array([ 2, 5, 10])
  4449. >>> np.multiply.accumulate([2, 3, 5])
  4450. array([ 2, 6, 30])
  4451. 2-D array examples:
  4452. >>> I = np.eye(2)
  4453. >>> I
  4454. array([[ 1., 0.],
  4455. [ 0., 1.]])
  4456. Accumulate along axis 0 (rows), down columns:
  4457. >>> np.add.accumulate(I, 0)
  4458. array([[ 1., 0.],
  4459. [ 1., 1.]])
  4460. >>> np.add.accumulate(I) # no axis specified = axis zero
  4461. array([[ 1., 0.],
  4462. [ 1., 1.]])
  4463. Accumulate along axis 1 (columns), through rows:
  4464. >>> np.add.accumulate(I, 1)
  4465. array([[ 1., 1.],
  4466. [ 0., 1.]])
  4467. """))
  4468. add_newdoc('numpy.core', 'ufunc', ('reduceat',
  4469. """
  4470. reduceat(a, indices, axis=0, dtype=None, out=None)
  4471. Performs a (local) reduce with specified slices over a single axis.
  4472. For i in ``range(len(indices))``, `reduceat` computes
  4473. ``ufunc.reduce(a[indices[i]:indices[i+1]])``, which becomes the i-th
  4474. generalized "row" parallel to `axis` in the final result (i.e., in a
  4475. 2-D array, for example, if `axis = 0`, it becomes the i-th row, but if
  4476. `axis = 1`, it becomes the i-th column). There are three exceptions to this:
  4477. * when ``i = len(indices) - 1`` (so for the last index),
  4478. ``indices[i+1] = a.shape[axis]``.
  4479. * if ``indices[i] >= indices[i + 1]``, the i-th generalized "row" is
  4480. simply ``a[indices[i]]``.
  4481. * if ``indices[i] >= len(a)`` or ``indices[i] < 0``, an error is raised.
  4482. The shape of the output depends on the size of `indices`, and may be
  4483. larger than `a` (this happens if ``len(indices) > a.shape[axis]``).
  4484. Parameters
  4485. ----------
  4486. a : array_like
  4487. The array to act on.
  4488. indices : array_like
  4489. Paired indices, comma separated (not colon), specifying slices to
  4490. reduce.
  4491. axis : int, optional
  4492. The axis along which to apply the reduceat.
  4493. dtype : data-type code, optional
  4494. The type used to represent the intermediate results. Defaults
  4495. to the data type of the output array if this is provided, or
  4496. the data type of the input array if no output array is provided.
  4497. out : ndarray, optional
  4498. A location into which the result is stored. If not provided a
  4499. freshly-allocated array is returned.
  4500. Returns
  4501. -------
  4502. r : ndarray
  4503. The reduced values. If `out` was supplied, `r` is a reference to
  4504. `out`.
  4505. Notes
  4506. -----
  4507. A descriptive example:
  4508. If `a` is 1-D, the function `ufunc.accumulate(a)` is the same as
  4509. ``ufunc.reduceat(a, indices)[::2]`` where `indices` is
  4510. ``range(len(array) - 1)`` with a zero placed
  4511. in every other element:
  4512. ``indices = zeros(2 * len(a) - 1)``, ``indices[1::2] = range(1, len(a))``.
  4513. Don't be fooled by this attribute's name: `reduceat(a)` is not
  4514. necessarily smaller than `a`.
  4515. Examples
  4516. --------
  4517. To take the running sum of four successive values:
  4518. >>> np.add.reduceat(np.arange(8),[0,4, 1,5, 2,6, 3,7])[::2]
  4519. array([ 6, 10, 14, 18])
  4520. A 2-D example:
  4521. >>> x = np.linspace(0, 15, 16).reshape(4,4)
  4522. >>> x
  4523. array([[ 0., 1., 2., 3.],
  4524. [ 4., 5., 6., 7.],
  4525. [ 8., 9., 10., 11.],
  4526. [ 12., 13., 14., 15.]])
  4527. ::
  4528. # reduce such that the result has the following five rows:
  4529. # [row1 + row2 + row3]
  4530. # [row4]
  4531. # [row2]
  4532. # [row3]
  4533. # [row1 + row2 + row3 + row4]
  4534. >>> np.add.reduceat(x, [0, 3, 1, 2, 0])
  4535. array([[ 12., 15., 18., 21.],
  4536. [ 12., 13., 14., 15.],
  4537. [ 4., 5., 6., 7.],
  4538. [ 8., 9., 10., 11.],
  4539. [ 24., 28., 32., 36.]])
  4540. ::
  4541. # reduce such that result has the following two columns:
  4542. # [col1 * col2 * col3, col4]
  4543. >>> np.multiply.reduceat(x, [0, 3], 1)
  4544. array([[ 0., 3.],
  4545. [ 120., 7.],
  4546. [ 720., 11.],
  4547. [ 2184., 15.]])
  4548. """))
  4549. add_newdoc('numpy.core', 'ufunc', ('outer',
  4550. """
  4551. outer(A, B)
  4552. Apply the ufunc `op` to all pairs (a, b) with a in `A` and b in `B`.
  4553. Let ``M = A.ndim``, ``N = B.ndim``. Then the result, `C`, of
  4554. ``op.outer(A, B)`` is an array of dimension M + N such that:
  4555. .. math:: C[i_0, ..., i_{M-1}, j_0, ..., j_{N-1}] =
  4556. op(A[i_0, ..., i_{M-1}], B[j_0, ..., j_{N-1}])
  4557. For `A` and `B` one-dimensional, this is equivalent to::
  4558. r = empty(len(A),len(B))
  4559. for i in range(len(A)):
  4560. for j in range(len(B)):
  4561. r[i,j] = op(A[i], B[j]) # op = ufunc in question
  4562. Parameters
  4563. ----------
  4564. A : array_like
  4565. First array
  4566. B : array_like
  4567. Second array
  4568. Returns
  4569. -------
  4570. r : ndarray
  4571. Output array
  4572. See Also
  4573. --------
  4574. numpy.outer
  4575. Examples
  4576. --------
  4577. >>> np.multiply.outer([1, 2, 3], [4, 5, 6])
  4578. array([[ 4, 5, 6],
  4579. [ 8, 10, 12],
  4580. [12, 15, 18]])
  4581. A multi-dimensional example:
  4582. >>> A = np.array([[1, 2, 3], [4, 5, 6]])
  4583. >>> A.shape
  4584. (2, 3)
  4585. >>> B = np.array([[1, 2, 3, 4]])
  4586. >>> B.shape
  4587. (1, 4)
  4588. >>> C = np.multiply.outer(A, B)
  4589. >>> C.shape; C
  4590. (2, 3, 1, 4)
  4591. array([[[[ 1, 2, 3, 4]],
  4592. [[ 2, 4, 6, 8]],
  4593. [[ 3, 6, 9, 12]]],
  4594. [[[ 4, 8, 12, 16]],
  4595. [[ 5, 10, 15, 20]],
  4596. [[ 6, 12, 18, 24]]]])
  4597. """))
  4598. add_newdoc('numpy.core', 'ufunc', ('at',
  4599. """
  4600. at(a, indices, b=None)
  4601. Performs unbuffered in place operation on operand 'a' for elements
  4602. specified by 'indices'. For addition ufunc, this method is equivalent to
  4603. `a[indices] += b`, except that results are accumulated for elements that
  4604. are indexed more than once. For example, `a[[0,0]] += 1` will only
  4605. increment the first element once because of buffering, whereas
  4606. `add.at(a, [0,0], 1)` will increment the first element twice.
  4607. .. versionadded:: 1.8.0
  4608. Parameters
  4609. ----------
  4610. a : array_like
  4611. The array to perform in place operation on.
  4612. indices : array_like or tuple
  4613. Array like index object or slice object for indexing into first
  4614. operand. If first operand has multiple dimensions, indices can be a
  4615. tuple of array like index objects or slice objects.
  4616. b : array_like
  4617. Second operand for ufuncs requiring two operands. Operand must be
  4618. broadcastable over first operand after indexing or slicing.
  4619. Examples
  4620. --------
  4621. Set items 0 and 1 to their negative values:
  4622. >>> a = np.array([1, 2, 3, 4])
  4623. >>> np.negative.at(a, [0, 1])
  4624. >>> print(a)
  4625. array([-1, -2, 3, 4])
  4626. ::
  4627. Increment items 0 and 1, and increment item 2 twice:
  4628. >>> a = np.array([1, 2, 3, 4])
  4629. >>> np.add.at(a, [0, 1, 2, 2], 1)
  4630. >>> print(a)
  4631. array([2, 3, 5, 4])
  4632. ::
  4633. Add items 0 and 1 in first array to second array,
  4634. and store results in first array:
  4635. >>> a = np.array([1, 2, 3, 4])
  4636. >>> b = np.array([1, 2])
  4637. >>> np.add.at(a, [0, 1], b)
  4638. >>> print(a)
  4639. array([2, 4, 3, 4])
  4640. """))
  4641. ##############################################################################
  4642. #
  4643. # Documentation for dtype attributes and methods
  4644. #
  4645. ##############################################################################
  4646. ##############################################################################
  4647. #
  4648. # dtype object
  4649. #
  4650. ##############################################################################
  4651. add_newdoc('numpy.core.multiarray', 'dtype',
  4652. """
  4653. dtype(obj, align=False, copy=False)
  4654. Create a data type object.
  4655. A numpy array is homogeneous, and contains elements described by a
  4656. dtype object. A dtype object can be constructed from different
  4657. combinations of fundamental numeric types.
  4658. Parameters
  4659. ----------
  4660. obj
  4661. Object to be converted to a data type object.
  4662. align : bool, optional
  4663. Add padding to the fields to match what a C compiler would output
  4664. for a similar C-struct. Can be ``True`` only if `obj` is a dictionary
  4665. or a comma-separated string. If a struct dtype is being created,
  4666. this also sets a sticky alignment flag ``isalignedstruct``.
  4667. copy : bool, optional
  4668. Make a new copy of the data-type object. If ``False``, the result
  4669. may just be a reference to a built-in data-type object.
  4670. See also
  4671. --------
  4672. result_type
  4673. Examples
  4674. --------
  4675. Using array-scalar type:
  4676. >>> np.dtype(np.int16)
  4677. dtype('int16')
  4678. Structured type, one field name 'f1', containing int16:
  4679. >>> np.dtype([('f1', np.int16)])
  4680. dtype([('f1', '<i2')])
  4681. Structured type, one field named 'f1', in itself containing a structured
  4682. type with one field:
  4683. >>> np.dtype([('f1', [('f1', np.int16)])])
  4684. dtype([('f1', [('f1', '<i2')])])
  4685. Structured type, two fields: the first field contains an unsigned int, the
  4686. second an int32:
  4687. >>> np.dtype([('f1', np.uint), ('f2', np.int32)])
  4688. dtype([('f1', '<u4'), ('f2', '<i4')])
  4689. Using array-protocol type strings:
  4690. >>> np.dtype([('a','f8'),('b','S10')])
  4691. dtype([('a', '<f8'), ('b', '|S10')])
  4692. Using comma-separated field formats. The shape is (2,3):
  4693. >>> np.dtype("i4, (2,3)f8")
  4694. dtype([('f0', '<i4'), ('f1', '<f8', (2, 3))])
  4695. Using tuples. ``int`` is a fixed type, 3 the field's shape. ``void``
  4696. is a flexible type, here of size 10:
  4697. >>> np.dtype([('hello',(np.int,3)),('world',np.void,10)])
  4698. dtype([('hello', '<i4', 3), ('world', '|V10')])
  4699. Subdivide ``int16`` into 2 ``int8``'s, called x and y. 0 and 1 are
  4700. the offsets in bytes:
  4701. >>> np.dtype((np.int16, {'x':(np.int8,0), 'y':(np.int8,1)}))
  4702. dtype(('<i2', [('x', '|i1'), ('y', '|i1')]))
  4703. Using dictionaries. Two fields named 'gender' and 'age':
  4704. >>> np.dtype({'names':['gender','age'], 'formats':['S1',np.uint8]})
  4705. dtype([('gender', '|S1'), ('age', '|u1')])
  4706. Offsets in bytes, here 0 and 25:
  4707. >>> np.dtype({'surname':('S25',0),'age':(np.uint8,25)})
  4708. dtype([('surname', '|S25'), ('age', '|u1')])
  4709. """)
  4710. ##############################################################################
  4711. #
  4712. # dtype attributes
  4713. #
  4714. ##############################################################################
  4715. add_newdoc('numpy.core.multiarray', 'dtype', ('alignment',
  4716. """
  4717. The required alignment (bytes) of this data-type according to the compiler.
  4718. More information is available in the C-API section of the manual.
  4719. """))
  4720. add_newdoc('numpy.core.multiarray', 'dtype', ('byteorder',
  4721. """
  4722. A character indicating the byte-order of this data-type object.
  4723. One of:
  4724. === ==============
  4725. '=' native
  4726. '<' little-endian
  4727. '>' big-endian
  4728. '|' not applicable
  4729. === ==============
  4730. All built-in data-type objects have byteorder either '=' or '|'.
  4731. Examples
  4732. --------
  4733. >>> dt = np.dtype('i2')
  4734. >>> dt.byteorder
  4735. '='
  4736. >>> # endian is not relevant for 8 bit numbers
  4737. >>> np.dtype('i1').byteorder
  4738. '|'
  4739. >>> # or ASCII strings
  4740. >>> np.dtype('S2').byteorder
  4741. '|'
  4742. >>> # Even if specific code is given, and it is native
  4743. >>> # '=' is the byteorder
  4744. >>> import sys
  4745. >>> sys_is_le = sys.byteorder == 'little'
  4746. >>> native_code = sys_is_le and '<' or '>'
  4747. >>> swapped_code = sys_is_le and '>' or '<'
  4748. >>> dt = np.dtype(native_code + 'i2')
  4749. >>> dt.byteorder
  4750. '='
  4751. >>> # Swapped code shows up as itself
  4752. >>> dt = np.dtype(swapped_code + 'i2')
  4753. >>> dt.byteorder == swapped_code
  4754. True
  4755. """))
  4756. add_newdoc('numpy.core.multiarray', 'dtype', ('char',
  4757. """A unique character code for each of the 21 different built-in types."""))
  4758. add_newdoc('numpy.core.multiarray', 'dtype', ('descr',
  4759. """
  4760. Array-interface compliant full description of the data-type.
  4761. The format is that required by the 'descr' key in the
  4762. `__array_interface__` attribute.
  4763. """))
  4764. add_newdoc('numpy.core.multiarray', 'dtype', ('fields',
  4765. """
  4766. Dictionary of named fields defined for this data type, or ``None``.
  4767. The dictionary is indexed by keys that are the names of the fields.
  4768. Each entry in the dictionary is a tuple fully describing the field::
  4769. (dtype, offset[, title])
  4770. If present, the optional title can be any object (if it is a string
  4771. or unicode then it will also be a key in the fields dictionary,
  4772. otherwise it's meta-data). Notice also that the first two elements
  4773. of the tuple can be passed directly as arguments to the ``ndarray.getfield``
  4774. and ``ndarray.setfield`` methods.
  4775. See Also
  4776. --------
  4777. ndarray.getfield, ndarray.setfield
  4778. Examples
  4779. --------
  4780. >>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))])
  4781. >>> print(dt.fields)
  4782. {'grades': (dtype(('float64',(2,))), 16), 'name': (dtype('|S16'), 0)}
  4783. """))
  4784. add_newdoc('numpy.core.multiarray', 'dtype', ('flags',
  4785. """
  4786. Bit-flags describing how this data type is to be interpreted.
  4787. Bit-masks are in `numpy.core.multiarray` as the constants
  4788. `ITEM_HASOBJECT`, `LIST_PICKLE`, `ITEM_IS_POINTER`, `NEEDS_INIT`,
  4789. `NEEDS_PYAPI`, `USE_GETITEM`, `USE_SETITEM`. A full explanation
  4790. of these flags is in C-API documentation; they are largely useful
  4791. for user-defined data-types.
  4792. """))
  4793. add_newdoc('numpy.core.multiarray', 'dtype', ('hasobject',
  4794. """
  4795. Boolean indicating whether this dtype contains any reference-counted
  4796. objects in any fields or sub-dtypes.
  4797. Recall that what is actually in the ndarray memory representing
  4798. the Python object is the memory address of that object (a pointer).
  4799. Special handling may be required, and this attribute is useful for
  4800. distinguishing data types that may contain arbitrary Python objects
  4801. and data-types that won't.
  4802. """))
  4803. add_newdoc('numpy.core.multiarray', 'dtype', ('isbuiltin',
  4804. """
  4805. Integer indicating how this dtype relates to the built-in dtypes.
  4806. Read-only.
  4807. = ========================================================================
  4808. 0 if this is a structured array type, with fields
  4809. 1 if this is a dtype compiled into numpy (such as ints, floats etc)
  4810. 2 if the dtype is for a user-defined numpy type
  4811. A user-defined type uses the numpy C-API machinery to extend
  4812. numpy to handle a new array type. See
  4813. :ref:`user.user-defined-data-types` in the Numpy manual.
  4814. = ========================================================================
  4815. Examples
  4816. --------
  4817. >>> dt = np.dtype('i2')
  4818. >>> dt.isbuiltin
  4819. 1
  4820. >>> dt = np.dtype('f8')
  4821. >>> dt.isbuiltin
  4822. 1
  4823. >>> dt = np.dtype([('field1', 'f8')])
  4824. >>> dt.isbuiltin
  4825. 0
  4826. """))
  4827. add_newdoc('numpy.core.multiarray', 'dtype', ('isnative',
  4828. """
  4829. Boolean indicating whether the byte order of this dtype is native
  4830. to the platform.
  4831. """))
  4832. add_newdoc('numpy.core.multiarray', 'dtype', ('isalignedstruct',
  4833. """
  4834. Boolean indicating whether the dtype is a struct which maintains
  4835. field alignment. This flag is sticky, so when combining multiple
  4836. structs together, it is preserved and produces new dtypes which
  4837. are also aligned.
  4838. """))
  4839. add_newdoc('numpy.core.multiarray', 'dtype', ('itemsize',
  4840. """
  4841. The element size of this data-type object.
  4842. For 18 of the 21 types this number is fixed by the data-type.
  4843. For the flexible data-types, this number can be anything.
  4844. """))
  4845. add_newdoc('numpy.core.multiarray', 'dtype', ('kind',
  4846. """
  4847. A character code (one of 'biufcmMOSUV') identifying the general kind of data.
  4848. = ======================
  4849. b boolean
  4850. i signed integer
  4851. u unsigned integer
  4852. f floating-point
  4853. c complex floating-point
  4854. m timedelta
  4855. M datetime
  4856. O object
  4857. S (byte-)string
  4858. U Unicode
  4859. V void
  4860. = ======================
  4861. """))
  4862. add_newdoc('numpy.core.multiarray', 'dtype', ('name',
  4863. """
  4864. A bit-width name for this data-type.
  4865. Un-sized flexible data-type objects do not have this attribute.
  4866. """))
  4867. add_newdoc('numpy.core.multiarray', 'dtype', ('names',
  4868. """
  4869. Ordered list of field names, or ``None`` if there are no fields.
  4870. The names are ordered according to increasing byte offset. This can be
  4871. used, for example, to walk through all of the named fields in offset order.
  4872. Examples
  4873. --------
  4874. >>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))])
  4875. >>> dt.names
  4876. ('name', 'grades')
  4877. """))
  4878. add_newdoc('numpy.core.multiarray', 'dtype', ('num',
  4879. """
  4880. A unique number for each of the 21 different built-in types.
  4881. These are roughly ordered from least-to-most precision.
  4882. """))
  4883. add_newdoc('numpy.core.multiarray', 'dtype', ('shape',
  4884. """
  4885. Shape tuple of the sub-array if this data type describes a sub-array,
  4886. and ``()`` otherwise.
  4887. """))
  4888. add_newdoc('numpy.core.multiarray', 'dtype', ('str',
  4889. """The array-protocol typestring of this data-type object."""))
  4890. add_newdoc('numpy.core.multiarray', 'dtype', ('subdtype',
  4891. """
  4892. Tuple ``(item_dtype, shape)`` if this `dtype` describes a sub-array, and
  4893. None otherwise.
  4894. The *shape* is the fixed shape of the sub-array described by this
  4895. data type, and *item_dtype* the data type of the array.
  4896. If a field whose dtype object has this attribute is retrieved,
  4897. then the extra dimensions implied by *shape* are tacked on to
  4898. the end of the retrieved array.
  4899. """))
  4900. add_newdoc('numpy.core.multiarray', 'dtype', ('type',
  4901. """The type object used to instantiate a scalar of this data-type."""))
  4902. ##############################################################################
  4903. #
  4904. # dtype methods
  4905. #
  4906. ##############################################################################
  4907. add_newdoc('numpy.core.multiarray', 'dtype', ('newbyteorder',
  4908. """
  4909. newbyteorder(new_order='S')
  4910. Return a new dtype with a different byte order.
  4911. Changes are also made in all fields and sub-arrays of the data type.
  4912. Parameters
  4913. ----------
  4914. new_order : string, optional
  4915. Byte order to force; a value from the byte order specifications
  4916. below. The default value ('S') results in swapping the current
  4917. byte order. `new_order` codes can be any of:
  4918. * 'S' - swap dtype from current to opposite endian
  4919. * {'<', 'L'} - little endian
  4920. * {'>', 'B'} - big endian
  4921. * {'=', 'N'} - native order
  4922. * {'|', 'I'} - ignore (no change to byte order)
  4923. The code does a case-insensitive check on the first letter of
  4924. `new_order` for these alternatives. For example, any of '>'
  4925. or 'B' or 'b' or 'brian' are valid to specify big-endian.
  4926. Returns
  4927. -------
  4928. new_dtype : dtype
  4929. New dtype object with the given change to the byte order.
  4930. Notes
  4931. -----
  4932. Changes are also made in all fields and sub-arrays of the data type.
  4933. Examples
  4934. --------
  4935. >>> import sys
  4936. >>> sys_is_le = sys.byteorder == 'little'
  4937. >>> native_code = sys_is_le and '<' or '>'
  4938. >>> swapped_code = sys_is_le and '>' or '<'
  4939. >>> native_dt = np.dtype(native_code+'i2')
  4940. >>> swapped_dt = np.dtype(swapped_code+'i2')
  4941. >>> native_dt.newbyteorder('S') == swapped_dt
  4942. True
  4943. >>> native_dt.newbyteorder() == swapped_dt
  4944. True
  4945. >>> native_dt == swapped_dt.newbyteorder('S')
  4946. True
  4947. >>> native_dt == swapped_dt.newbyteorder('=')
  4948. True
  4949. >>> native_dt == swapped_dt.newbyteorder('N')
  4950. True
  4951. >>> native_dt == native_dt.newbyteorder('|')
  4952. True
  4953. >>> np.dtype('<i2') == native_dt.newbyteorder('<')
  4954. True
  4955. >>> np.dtype('<i2') == native_dt.newbyteorder('L')
  4956. True
  4957. >>> np.dtype('>i2') == native_dt.newbyteorder('>')
  4958. True
  4959. >>> np.dtype('>i2') == native_dt.newbyteorder('B')
  4960. True
  4961. """))
  4962. ##############################################################################
  4963. #
  4964. # Datetime-related Methods
  4965. #
  4966. ##############################################################################
  4967. add_newdoc('numpy.core.multiarray', 'busdaycalendar',
  4968. """
  4969. busdaycalendar(weekmask='1111100', holidays=None)
  4970. A business day calendar object that efficiently stores information
  4971. defining valid days for the busday family of functions.
  4972. The default valid days are Monday through Friday ("business days").
  4973. A busdaycalendar object can be specified with any set of weekly
  4974. valid days, plus an optional "holiday" dates that always will be invalid.
  4975. Once a busdaycalendar object is created, the weekmask and holidays
  4976. cannot be modified.
  4977. .. versionadded:: 1.7.0
  4978. Parameters
  4979. ----------
  4980. weekmask : str or array_like of bool, optional
  4981. A seven-element array indicating which of Monday through Sunday are
  4982. valid days. May be specified as a length-seven list or array, like
  4983. [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string
  4984. like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for
  4985. weekdays, optionally separated by white space. Valid abbreviations
  4986. are: Mon Tue Wed Thu Fri Sat Sun
  4987. holidays : array_like of datetime64[D], optional
  4988. An array of dates to consider as invalid dates, no matter which
  4989. weekday they fall upon. Holiday dates may be specified in any
  4990. order, and NaT (not-a-time) dates are ignored. This list is
  4991. saved in a normalized form that is suited for fast calculations
  4992. of valid days.
  4993. Returns
  4994. -------
  4995. out : busdaycalendar
  4996. A business day calendar object containing the specified
  4997. weekmask and holidays values.
  4998. See Also
  4999. --------
  5000. is_busday : Returns a boolean array indicating valid days.
  5001. busday_offset : Applies an offset counted in valid days.
  5002. busday_count : Counts how many valid days are in a half-open date range.
  5003. Attributes
  5004. ----------
  5005. Note: once a busdaycalendar object is created, you cannot modify the
  5006. weekmask or holidays. The attributes return copies of internal data.
  5007. weekmask : (copy) seven-element array of bool
  5008. holidays : (copy) sorted array of datetime64[D]
  5009. Examples
  5010. --------
  5011. >>> # Some important days in July
  5012. ... bdd = np.busdaycalendar(
  5013. ... holidays=['2011-07-01', '2011-07-04', '2011-07-17'])
  5014. >>> # Default is Monday to Friday weekdays
  5015. ... bdd.weekmask
  5016. array([ True, True, True, True, True, False, False], dtype='bool')
  5017. >>> # Any holidays already on the weekend are removed
  5018. ... bdd.holidays
  5019. array(['2011-07-01', '2011-07-04'], dtype='datetime64[D]')
  5020. """)
  5021. add_newdoc('numpy.core.multiarray', 'busdaycalendar', ('weekmask',
  5022. """A copy of the seven-element boolean mask indicating valid days."""))
  5023. add_newdoc('numpy.core.multiarray', 'busdaycalendar', ('holidays',
  5024. """A copy of the holiday array indicating additional invalid days."""))
  5025. add_newdoc('numpy.core.multiarray', 'is_busday',
  5026. """
  5027. is_busday(dates, weekmask='1111100', holidays=None, busdaycal=None, out=None)
  5028. Calculates which of the given dates are valid days, and which are not.
  5029. .. versionadded:: 1.7.0
  5030. Parameters
  5031. ----------
  5032. dates : array_like of datetime64[D]
  5033. The array of dates to process.
  5034. weekmask : str or array_like of bool, optional
  5035. A seven-element array indicating which of Monday through Sunday are
  5036. valid days. May be specified as a length-seven list or array, like
  5037. [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string
  5038. like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for
  5039. weekdays, optionally separated by white space. Valid abbreviations
  5040. are: Mon Tue Wed Thu Fri Sat Sun
  5041. holidays : array_like of datetime64[D], optional
  5042. An array of dates to consider as invalid dates. They may be
  5043. specified in any order, and NaT (not-a-time) dates are ignored.
  5044. This list is saved in a normalized form that is suited for
  5045. fast calculations of valid days.
  5046. busdaycal : busdaycalendar, optional
  5047. A `busdaycalendar` object which specifies the valid days. If this
  5048. parameter is provided, neither weekmask nor holidays may be
  5049. provided.
  5050. out : array of bool, optional
  5051. If provided, this array is filled with the result.
  5052. Returns
  5053. -------
  5054. out : array of bool
  5055. An array with the same shape as ``dates``, containing True for
  5056. each valid day, and False for each invalid day.
  5057. See Also
  5058. --------
  5059. busdaycalendar: An object that specifies a custom set of valid days.
  5060. busday_offset : Applies an offset counted in valid days.
  5061. busday_count : Counts how many valid days are in a half-open date range.
  5062. Examples
  5063. --------
  5064. >>> # The weekdays are Friday, Saturday, and Monday
  5065. ... np.is_busday(['2011-07-01', '2011-07-02', '2011-07-18'],
  5066. ... holidays=['2011-07-01', '2011-07-04', '2011-07-17'])
  5067. array([False, False, True], dtype='bool')
  5068. """)
  5069. add_newdoc('numpy.core.multiarray', 'busday_offset',
  5070. """
  5071. busday_offset(dates, offsets, roll='raise', weekmask='1111100', holidays=None, busdaycal=None, out=None)
  5072. First adjusts the date to fall on a valid day according to
  5073. the ``roll`` rule, then applies offsets to the given dates
  5074. counted in valid days.
  5075. .. versionadded:: 1.7.0
  5076. Parameters
  5077. ----------
  5078. dates : array_like of datetime64[D]
  5079. The array of dates to process.
  5080. offsets : array_like of int
  5081. The array of offsets, which is broadcast with ``dates``.
  5082. roll : {'raise', 'nat', 'forward', 'following', 'backward', 'preceding', 'modifiedfollowing', 'modifiedpreceding'}, optional
  5083. How to treat dates that do not fall on a valid day. The default
  5084. is 'raise'.
  5085. * 'raise' means to raise an exception for an invalid day.
  5086. * 'nat' means to return a NaT (not-a-time) for an invalid day.
  5087. * 'forward' and 'following' mean to take the first valid day
  5088. later in time.
  5089. * 'backward' and 'preceding' mean to take the first valid day
  5090. earlier in time.
  5091. * 'modifiedfollowing' means to take the first valid day
  5092. later in time unless it is across a Month boundary, in which
  5093. case to take the first valid day earlier in time.
  5094. * 'modifiedpreceding' means to take the first valid day
  5095. earlier in time unless it is across a Month boundary, in which
  5096. case to take the first valid day later in time.
  5097. weekmask : str or array_like of bool, optional
  5098. A seven-element array indicating which of Monday through Sunday are
  5099. valid days. May be specified as a length-seven list or array, like
  5100. [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string
  5101. like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for
  5102. weekdays, optionally separated by white space. Valid abbreviations
  5103. are: Mon Tue Wed Thu Fri Sat Sun
  5104. holidays : array_like of datetime64[D], optional
  5105. An array of dates to consider as invalid dates. They may be
  5106. specified in any order, and NaT (not-a-time) dates are ignored.
  5107. This list is saved in a normalized form that is suited for
  5108. fast calculations of valid days.
  5109. busdaycal : busdaycalendar, optional
  5110. A `busdaycalendar` object which specifies the valid days. If this
  5111. parameter is provided, neither weekmask nor holidays may be
  5112. provided.
  5113. out : array of datetime64[D], optional
  5114. If provided, this array is filled with the result.
  5115. Returns
  5116. -------
  5117. out : array of datetime64[D]
  5118. An array with a shape from broadcasting ``dates`` and ``offsets``
  5119. together, containing the dates with offsets applied.
  5120. See Also
  5121. --------
  5122. busdaycalendar: An object that specifies a custom set of valid days.
  5123. is_busday : Returns a boolean array indicating valid days.
  5124. busday_count : Counts how many valid days are in a half-open date range.
  5125. Examples
  5126. --------
  5127. >>> # First business day in October 2011 (not accounting for holidays)
  5128. ... np.busday_offset('2011-10', 0, roll='forward')
  5129. numpy.datetime64('2011-10-03','D')
  5130. >>> # Last business day in February 2012 (not accounting for holidays)
  5131. ... np.busday_offset('2012-03', -1, roll='forward')
  5132. numpy.datetime64('2012-02-29','D')
  5133. >>> # Third Wednesday in January 2011
  5134. ... np.busday_offset('2011-01', 2, roll='forward', weekmask='Wed')
  5135. numpy.datetime64('2011-01-19','D')
  5136. >>> # 2012 Mother's Day in Canada and the U.S.
  5137. ... np.busday_offset('2012-05', 1, roll='forward', weekmask='Sun')
  5138. numpy.datetime64('2012-05-13','D')
  5139. >>> # First business day on or after a date
  5140. ... np.busday_offset('2011-03-20', 0, roll='forward')
  5141. numpy.datetime64('2011-03-21','D')
  5142. >>> np.busday_offset('2011-03-22', 0, roll='forward')
  5143. numpy.datetime64('2011-03-22','D')
  5144. >>> # First business day after a date
  5145. ... np.busday_offset('2011-03-20', 1, roll='backward')
  5146. numpy.datetime64('2011-03-21','D')
  5147. >>> np.busday_offset('2011-03-22', 1, roll='backward')
  5148. numpy.datetime64('2011-03-23','D')
  5149. """)
  5150. add_newdoc('numpy.core.multiarray', 'busday_count',
  5151. """
  5152. busday_count(begindates, enddates, weekmask='1111100', holidays=[], busdaycal=None, out=None)
  5153. Counts the number of valid days between `begindates` and
  5154. `enddates`, not including the day of `enddates`.
  5155. If ``enddates`` specifies a date value that is earlier than the
  5156. corresponding ``begindates`` date value, the count will be negative.
  5157. .. versionadded:: 1.7.0
  5158. Parameters
  5159. ----------
  5160. begindates : array_like of datetime64[D]
  5161. The array of the first dates for counting.
  5162. enddates : array_like of datetime64[D]
  5163. The array of the end dates for counting, which are excluded
  5164. from the count themselves.
  5165. weekmask : str or array_like of bool, optional
  5166. A seven-element array indicating which of Monday through Sunday are
  5167. valid days. May be specified as a length-seven list or array, like
  5168. [1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string
  5169. like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for
  5170. weekdays, optionally separated by white space. Valid abbreviations
  5171. are: Mon Tue Wed Thu Fri Sat Sun
  5172. holidays : array_like of datetime64[D], optional
  5173. An array of dates to consider as invalid dates. They may be
  5174. specified in any order, and NaT (not-a-time) dates are ignored.
  5175. This list is saved in a normalized form that is suited for
  5176. fast calculations of valid days.
  5177. busdaycal : busdaycalendar, optional
  5178. A `busdaycalendar` object which specifies the valid days. If this
  5179. parameter is provided, neither weekmask nor holidays may be
  5180. provided.
  5181. out : array of int, optional
  5182. If provided, this array is filled with the result.
  5183. Returns
  5184. -------
  5185. out : array of int
  5186. An array with a shape from broadcasting ``begindates`` and ``enddates``
  5187. together, containing the number of valid days between
  5188. the begin and end dates.
  5189. See Also
  5190. --------
  5191. busdaycalendar: An object that specifies a custom set of valid days.
  5192. is_busday : Returns a boolean array indicating valid days.
  5193. busday_offset : Applies an offset counted in valid days.
  5194. Examples
  5195. --------
  5196. >>> # Number of weekdays in January 2011
  5197. ... np.busday_count('2011-01', '2011-02')
  5198. 21
  5199. >>> # Number of weekdays in 2011
  5200. ... np.busday_count('2011', '2012')
  5201. 260
  5202. >>> # Number of Saturdays in 2011
  5203. ... np.busday_count('2011', '2012', weekmask='Sat')
  5204. 53
  5205. """)
  5206. ##############################################################################
  5207. #
  5208. # nd_grid instances
  5209. #
  5210. ##############################################################################
  5211. add_newdoc('numpy.lib.index_tricks', 'mgrid',
  5212. """
  5213. `nd_grid` instance which returns a dense multi-dimensional "meshgrid".
  5214. An instance of `numpy.lib.index_tricks.nd_grid` which returns an dense
  5215. (or fleshed out) mesh-grid when indexed, so that each returned argument
  5216. has the same shape. The dimensions and number of the output arrays are
  5217. equal to the number of indexing dimensions. If the step length is not a
  5218. complex number, then the stop is not inclusive.
  5219. However, if the step length is a **complex number** (e.g. 5j), then
  5220. the integer part of its magnitude is interpreted as specifying the
  5221. number of points to create between the start and stop values, where
  5222. the stop value **is inclusive**.
  5223. Returns
  5224. ----------
  5225. mesh-grid `ndarrays` all of the same dimensions
  5226. See Also
  5227. --------
  5228. numpy.lib.index_tricks.nd_grid : class of `ogrid` and `mgrid` objects
  5229. ogrid : like mgrid but returns open (not fleshed out) mesh grids
  5230. r_ : array concatenator
  5231. Examples
  5232. --------
  5233. >>> np.mgrid[0:5,0:5]
  5234. array([[[0, 0, 0, 0, 0],
  5235. [1, 1, 1, 1, 1],
  5236. [2, 2, 2, 2, 2],
  5237. [3, 3, 3, 3, 3],
  5238. [4, 4, 4, 4, 4]],
  5239. [[0, 1, 2, 3, 4],
  5240. [0, 1, 2, 3, 4],
  5241. [0, 1, 2, 3, 4],
  5242. [0, 1, 2, 3, 4],
  5243. [0, 1, 2, 3, 4]]])
  5244. >>> np.mgrid[-1:1:5j]
  5245. array([-1. , -0.5, 0. , 0.5, 1. ])
  5246. """)
  5247. add_newdoc('numpy.lib.index_tricks', 'ogrid',
  5248. """
  5249. `nd_grid` instance which returns an open multi-dimensional "meshgrid".
  5250. An instance of `numpy.lib.index_tricks.nd_grid` which returns an open
  5251. (i.e. not fleshed out) mesh-grid when indexed, so that only one dimension
  5252. of each returned array is greater than 1. The dimension and number of the
  5253. output arrays are equal to the number of indexing dimensions. If the step
  5254. length is not a complex number, then the stop is not inclusive.
  5255. However, if the step length is a **complex number** (e.g. 5j), then
  5256. the integer part of its magnitude is interpreted as specifying the
  5257. number of points to create between the start and stop values, where
  5258. the stop value **is inclusive**.
  5259. Returns
  5260. ----------
  5261. mesh-grid `ndarrays` with only one dimension :math:`\\neq 1`
  5262. See Also
  5263. --------
  5264. np.lib.index_tricks.nd_grid : class of `ogrid` and `mgrid` objects
  5265. mgrid : like `ogrid` but returns dense (or fleshed out) mesh grids
  5266. r_ : array concatenator
  5267. Examples
  5268. --------
  5269. >>> from numpy import ogrid
  5270. >>> ogrid[-1:1:5j]
  5271. array([-1. , -0.5, 0. , 0.5, 1. ])
  5272. >>> ogrid[0:5,0:5]
  5273. [array([[0],
  5274. [1],
  5275. [2],
  5276. [3],
  5277. [4]]), array([[0, 1, 2, 3, 4]])]
  5278. """)
  5279. ##############################################################################
  5280. #
  5281. # Documentation for `generic` attributes and methods
  5282. #
  5283. ##############################################################################
  5284. add_newdoc('numpy.core.numerictypes', 'generic',
  5285. """
  5286. Base class for numpy scalar types.
  5287. Class from which most (all?) numpy scalar types are derived. For
  5288. consistency, exposes the same API as `ndarray`, despite many
  5289. consequent attributes being either "get-only," or completely irrelevant.
  5290. This is the class from which it is strongly suggested users should derive
  5291. custom scalar types.
  5292. """)
  5293. # Attributes
  5294. add_newdoc('numpy.core.numerictypes', 'generic', ('T',
  5295. """
  5296. Not implemented (virtual attribute)
  5297. Class generic exists solely to derive numpy scalars from, and possesses,
  5298. albeit unimplemented, all the attributes of the ndarray class so as to
  5299. provide a uniform API.
  5300. See Also
  5301. --------
  5302. The corresponding attribute of the derived class of interest.
  5303. """))
  5304. add_newdoc('numpy.core.numerictypes', 'generic', ('base',
  5305. """
  5306. Not implemented (virtual attribute)
  5307. Class generic exists solely to derive numpy scalars from, and possesses,
  5308. albeit unimplemented, all the attributes of the ndarray class so as to
  5309. a uniform API.
  5310. See Also
  5311. --------
  5312. The corresponding attribute of the derived class of interest.
  5313. """))
  5314. add_newdoc('numpy.core.numerictypes', 'generic', ('data',
  5315. """Pointer to start of data."""))
  5316. add_newdoc('numpy.core.numerictypes', 'generic', ('dtype',
  5317. """Get array data-descriptor."""))
  5318. add_newdoc('numpy.core.numerictypes', 'generic', ('flags',
  5319. """The integer value of flags."""))
  5320. add_newdoc('numpy.core.numerictypes', 'generic', ('flat',
  5321. """A 1-D view of the scalar."""))
  5322. add_newdoc('numpy.core.numerictypes', 'generic', ('imag',
  5323. """The imaginary part of the scalar."""))
  5324. add_newdoc('numpy.core.numerictypes', 'generic', ('itemsize',
  5325. """The length of one element in bytes."""))
  5326. add_newdoc('numpy.core.numerictypes', 'generic', ('nbytes',
  5327. """The length of the scalar in bytes."""))
  5328. add_newdoc('numpy.core.numerictypes', 'generic', ('ndim',
  5329. """The number of array dimensions."""))
  5330. add_newdoc('numpy.core.numerictypes', 'generic', ('real',
  5331. """The real part of the scalar."""))
  5332. add_newdoc('numpy.core.numerictypes', 'generic', ('shape',
  5333. """Tuple of array dimensions."""))
  5334. add_newdoc('numpy.core.numerictypes', 'generic', ('size',
  5335. """The number of elements in the gentype."""))
  5336. add_newdoc('numpy.core.numerictypes', 'generic', ('strides',
  5337. """Tuple of bytes steps in each dimension."""))
  5338. # Methods
  5339. add_newdoc('numpy.core.numerictypes', 'generic', ('all',
  5340. """
  5341. Not implemented (virtual attribute)
  5342. Class generic exists solely to derive numpy scalars from, and possesses,
  5343. albeit unimplemented, all the attributes of the ndarray class
  5344. so as to provide a uniform API.
  5345. See Also
  5346. --------
  5347. The corresponding attribute of the derived class of interest.
  5348. """))
  5349. add_newdoc('numpy.core.numerictypes', 'generic', ('any',
  5350. """
  5351. Not implemented (virtual attribute)
  5352. Class generic exists solely to derive numpy scalars from, and possesses,
  5353. albeit unimplemented, all the attributes of the ndarray class
  5354. so as to provide a uniform API.
  5355. See Also
  5356. --------
  5357. The corresponding attribute of the derived class of interest.
  5358. """))
  5359. add_newdoc('numpy.core.numerictypes', 'generic', ('argmax',
  5360. """
  5361. Not implemented (virtual attribute)
  5362. Class generic exists solely to derive numpy scalars from, and possesses,
  5363. albeit unimplemented, all the attributes of the ndarray class
  5364. so as to provide a uniform API.
  5365. See Also
  5366. --------
  5367. The corresponding attribute of the derived class of interest.
  5368. """))
  5369. add_newdoc('numpy.core.numerictypes', 'generic', ('argmin',
  5370. """
  5371. Not implemented (virtual attribute)
  5372. Class generic exists solely to derive numpy scalars from, and possesses,
  5373. albeit unimplemented, all the attributes of the ndarray class
  5374. so as to provide a uniform API.
  5375. See Also
  5376. --------
  5377. The corresponding attribute of the derived class of interest.
  5378. """))
  5379. add_newdoc('numpy.core.numerictypes', 'generic', ('argsort',
  5380. """
  5381. Not implemented (virtual attribute)
  5382. Class generic exists solely to derive numpy scalars from, and possesses,
  5383. albeit unimplemented, all the attributes of the ndarray class
  5384. so as to provide a uniform API.
  5385. See Also
  5386. --------
  5387. The corresponding attribute of the derived class of interest.
  5388. """))
  5389. add_newdoc('numpy.core.numerictypes', 'generic', ('astype',
  5390. """
  5391. Not implemented (virtual attribute)
  5392. Class generic exists solely to derive numpy scalars from, and possesses,
  5393. albeit unimplemented, all the attributes of the ndarray class
  5394. so as to provide a uniform API.
  5395. See Also
  5396. --------
  5397. The corresponding attribute of the derived class of interest.
  5398. """))
  5399. add_newdoc('numpy.core.numerictypes', 'generic', ('byteswap',
  5400. """
  5401. Not implemented (virtual attribute)
  5402. Class generic exists solely to derive numpy scalars from, and possesses,
  5403. albeit unimplemented, all the attributes of the ndarray class so as to
  5404. provide a uniform API.
  5405. See Also
  5406. --------
  5407. The corresponding attribute of the derived class of interest.
  5408. """))
  5409. add_newdoc('numpy.core.numerictypes', 'generic', ('choose',
  5410. """
  5411. Not implemented (virtual attribute)
  5412. Class generic exists solely to derive numpy scalars from, and possesses,
  5413. albeit unimplemented, all the attributes of the ndarray class
  5414. so as to provide a uniform API.
  5415. See Also
  5416. --------
  5417. The corresponding attribute of the derived class of interest.
  5418. """))
  5419. add_newdoc('numpy.core.numerictypes', 'generic', ('clip',
  5420. """
  5421. Not implemented (virtual attribute)
  5422. Class generic exists solely to derive numpy scalars from, and possesses,
  5423. albeit unimplemented, all the attributes of the ndarray class
  5424. so as to provide a uniform API.
  5425. See Also
  5426. --------
  5427. The corresponding attribute of the derived class of interest.
  5428. """))
  5429. add_newdoc('numpy.core.numerictypes', 'generic', ('compress',
  5430. """
  5431. Not implemented (virtual attribute)
  5432. Class generic exists solely to derive numpy scalars from, and possesses,
  5433. albeit unimplemented, all the attributes of the ndarray class
  5434. so as to provide a uniform API.
  5435. See Also
  5436. --------
  5437. The corresponding attribute of the derived class of interest.
  5438. """))
  5439. add_newdoc('numpy.core.numerictypes', 'generic', ('conjugate',
  5440. """
  5441. Not implemented (virtual attribute)
  5442. Class generic exists solely to derive numpy scalars from, and possesses,
  5443. albeit unimplemented, all the attributes of the ndarray class
  5444. so as to provide a uniform API.
  5445. See Also
  5446. --------
  5447. The corresponding attribute of the derived class of interest.
  5448. """))
  5449. add_newdoc('numpy.core.numerictypes', 'generic', ('copy',
  5450. """
  5451. Not implemented (virtual attribute)
  5452. Class generic exists solely to derive numpy scalars from, and possesses,
  5453. albeit unimplemented, all the attributes of the ndarray class
  5454. so as to provide a uniform API.
  5455. See Also
  5456. --------
  5457. The corresponding attribute of the derived class of interest.
  5458. """))
  5459. add_newdoc('numpy.core.numerictypes', 'generic', ('cumprod',
  5460. """
  5461. Not implemented (virtual attribute)
  5462. Class generic exists solely to derive numpy scalars from, and possesses,
  5463. albeit unimplemented, all the attributes of the ndarray class
  5464. so as to provide a uniform API.
  5465. See Also
  5466. --------
  5467. The corresponding attribute of the derived class of interest.
  5468. """))
  5469. add_newdoc('numpy.core.numerictypes', 'generic', ('cumsum',
  5470. """
  5471. Not implemented (virtual attribute)
  5472. Class generic exists solely to derive numpy scalars from, and possesses,
  5473. albeit unimplemented, all the attributes of the ndarray class
  5474. so as to provide a uniform API.
  5475. See Also
  5476. --------
  5477. The corresponding attribute of the derived class of interest.
  5478. """))
  5479. add_newdoc('numpy.core.numerictypes', 'generic', ('diagonal',
  5480. """
  5481. Not implemented (virtual attribute)
  5482. Class generic exists solely to derive numpy scalars from, and possesses,
  5483. albeit unimplemented, all the attributes of the ndarray class
  5484. so as to provide a uniform API.
  5485. See Also
  5486. --------
  5487. The corresponding attribute of the derived class of interest.
  5488. """))
  5489. add_newdoc('numpy.core.numerictypes', 'generic', ('dump',
  5490. """
  5491. Not implemented (virtual attribute)
  5492. Class generic exists solely to derive numpy scalars from, and possesses,
  5493. albeit unimplemented, all the attributes of the ndarray class
  5494. so as to provide a uniform API.
  5495. See Also
  5496. --------
  5497. The corresponding attribute of the derived class of interest.
  5498. """))
  5499. add_newdoc('numpy.core.numerictypes', 'generic', ('dumps',
  5500. """
  5501. Not implemented (virtual attribute)
  5502. Class generic exists solely to derive numpy scalars from, and possesses,
  5503. albeit unimplemented, all the attributes of the ndarray class
  5504. so as to provide a uniform API.
  5505. See Also
  5506. --------
  5507. The corresponding attribute of the derived class of interest.
  5508. """))
  5509. add_newdoc('numpy.core.numerictypes', 'generic', ('fill',
  5510. """
  5511. Not implemented (virtual attribute)
  5512. Class generic exists solely to derive numpy scalars from, and possesses,
  5513. albeit unimplemented, all the attributes of the ndarray class
  5514. so as to provide a uniform API.
  5515. See Also
  5516. --------
  5517. The corresponding attribute of the derived class of interest.
  5518. """))
  5519. add_newdoc('numpy.core.numerictypes', 'generic', ('flatten',
  5520. """
  5521. Not implemented (virtual attribute)
  5522. Class generic exists solely to derive numpy scalars from, and possesses,
  5523. albeit unimplemented, all the attributes of the ndarray class
  5524. so as to provide a uniform API.
  5525. See Also
  5526. --------
  5527. The corresponding attribute of the derived class of interest.
  5528. """))
  5529. add_newdoc('numpy.core.numerictypes', 'generic', ('getfield',
  5530. """
  5531. Not implemented (virtual attribute)
  5532. Class generic exists solely to derive numpy scalars from, and possesses,
  5533. albeit unimplemented, all the attributes of the ndarray class
  5534. so as to provide a uniform API.
  5535. See Also
  5536. --------
  5537. The corresponding attribute of the derived class of interest.
  5538. """))
  5539. add_newdoc('numpy.core.numerictypes', 'generic', ('item',
  5540. """
  5541. Not implemented (virtual attribute)
  5542. Class generic exists solely to derive numpy scalars from, and possesses,
  5543. albeit unimplemented, all the attributes of the ndarray class
  5544. so as to provide a uniform API.
  5545. See Also
  5546. --------
  5547. The corresponding attribute of the derived class of interest.
  5548. """))
  5549. add_newdoc('numpy.core.numerictypes', 'generic', ('itemset',
  5550. """
  5551. Not implemented (virtual attribute)
  5552. Class generic exists solely to derive numpy scalars from, and possesses,
  5553. albeit unimplemented, all the attributes of the ndarray class
  5554. so as to provide a uniform API.
  5555. See Also
  5556. --------
  5557. The corresponding attribute of the derived class of interest.
  5558. """))
  5559. add_newdoc('numpy.core.numerictypes', 'generic', ('max',
  5560. """
  5561. Not implemented (virtual attribute)
  5562. Class generic exists solely to derive numpy scalars from, and possesses,
  5563. albeit unimplemented, all the attributes of the ndarray class
  5564. so as to provide a uniform API.
  5565. See Also
  5566. --------
  5567. The corresponding attribute of the derived class of interest.
  5568. """))
  5569. add_newdoc('numpy.core.numerictypes', 'generic', ('mean',
  5570. """
  5571. Not implemented (virtual attribute)
  5572. Class generic exists solely to derive numpy scalars from, and possesses,
  5573. albeit unimplemented, all the attributes of the ndarray class
  5574. so as to provide a uniform API.
  5575. See Also
  5576. --------
  5577. The corresponding attribute of the derived class of interest.
  5578. """))
  5579. add_newdoc('numpy.core.numerictypes', 'generic', ('min',
  5580. """
  5581. Not implemented (virtual attribute)
  5582. Class generic exists solely to derive numpy scalars from, and possesses,
  5583. albeit unimplemented, all the attributes of the ndarray class
  5584. so as to provide a uniform API.
  5585. See Also
  5586. --------
  5587. The corresponding attribute of the derived class of interest.
  5588. """))
  5589. add_newdoc('numpy.core.numerictypes', 'generic', ('newbyteorder',
  5590. """
  5591. newbyteorder(new_order='S')
  5592. Return a new `dtype` with a different byte order.
  5593. Changes are also made in all fields and sub-arrays of the data type.
  5594. The `new_order` code can be any from the following:
  5595. * 'S' - swap dtype from current to opposite endian
  5596. * {'<', 'L'} - little endian
  5597. * {'>', 'B'} - big endian
  5598. * {'=', 'N'} - native order
  5599. * {'|', 'I'} - ignore (no change to byte order)
  5600. Parameters
  5601. ----------
  5602. new_order : str, optional
  5603. Byte order to force; a value from the byte order specifications
  5604. above. The default value ('S') results in swapping the current
  5605. byte order. The code does a case-insensitive check on the first
  5606. letter of `new_order` for the alternatives above. For example,
  5607. any of 'B' or 'b' or 'biggish' are valid to specify big-endian.
  5608. Returns
  5609. -------
  5610. new_dtype : dtype
  5611. New `dtype` object with the given change to the byte order.
  5612. """))
  5613. add_newdoc('numpy.core.numerictypes', 'generic', ('nonzero',
  5614. """
  5615. Not implemented (virtual attribute)
  5616. Class generic exists solely to derive numpy scalars from, and possesses,
  5617. albeit unimplemented, all the attributes of the ndarray class
  5618. so as to provide a uniform API.
  5619. See Also
  5620. --------
  5621. The corresponding attribute of the derived class of interest.
  5622. """))
  5623. add_newdoc('numpy.core.numerictypes', 'generic', ('prod',
  5624. """
  5625. Not implemented (virtual attribute)
  5626. Class generic exists solely to derive numpy scalars from, and possesses,
  5627. albeit unimplemented, all the attributes of the ndarray class
  5628. so as to provide a uniform API.
  5629. See Also
  5630. --------
  5631. The corresponding attribute of the derived class of interest.
  5632. """))
  5633. add_newdoc('numpy.core.numerictypes', 'generic', ('ptp',
  5634. """
  5635. Not implemented (virtual attribute)
  5636. Class generic exists solely to derive numpy scalars from, and possesses,
  5637. albeit unimplemented, all the attributes of the ndarray class
  5638. so as to provide a uniform API.
  5639. See Also
  5640. --------
  5641. The corresponding attribute of the derived class of interest.
  5642. """))
  5643. add_newdoc('numpy.core.numerictypes', 'generic', ('put',
  5644. """
  5645. Not implemented (virtual attribute)
  5646. Class generic exists solely to derive numpy scalars from, and possesses,
  5647. albeit unimplemented, all the attributes of the ndarray class
  5648. so as to provide a uniform API.
  5649. See Also
  5650. --------
  5651. The corresponding attribute of the derived class of interest.
  5652. """))
  5653. add_newdoc('numpy.core.numerictypes', 'generic', ('ravel',
  5654. """
  5655. Not implemented (virtual attribute)
  5656. Class generic exists solely to derive numpy scalars from, and possesses,
  5657. albeit unimplemented, all the attributes of the ndarray class
  5658. so as to provide a uniform API.
  5659. See Also
  5660. --------
  5661. The corresponding attribute of the derived class of interest.
  5662. """))
  5663. add_newdoc('numpy.core.numerictypes', 'generic', ('repeat',
  5664. """
  5665. Not implemented (virtual attribute)
  5666. Class generic exists solely to derive numpy scalars from, and possesses,
  5667. albeit unimplemented, all the attributes of the ndarray class
  5668. so as to provide a uniform API.
  5669. See Also
  5670. --------
  5671. The corresponding attribute of the derived class of interest.
  5672. """))
  5673. add_newdoc('numpy.core.numerictypes', 'generic', ('reshape',
  5674. """
  5675. Not implemented (virtual attribute)
  5676. Class generic exists solely to derive numpy scalars from, and possesses,
  5677. albeit unimplemented, all the attributes of the ndarray class
  5678. so as to provide a uniform API.
  5679. See Also
  5680. --------
  5681. The corresponding attribute of the derived class of interest.
  5682. """))
  5683. add_newdoc('numpy.core.numerictypes', 'generic', ('resize',
  5684. """
  5685. Not implemented (virtual attribute)
  5686. Class generic exists solely to derive numpy scalars from, and possesses,
  5687. albeit unimplemented, all the attributes of the ndarray class
  5688. so as to provide a uniform API.
  5689. See Also
  5690. --------
  5691. The corresponding attribute of the derived class of interest.
  5692. """))
  5693. add_newdoc('numpy.core.numerictypes', 'generic', ('round',
  5694. """
  5695. Not implemented (virtual attribute)
  5696. Class generic exists solely to derive numpy scalars from, and possesses,
  5697. albeit unimplemented, all the attributes of the ndarray class
  5698. so as to provide a uniform API.
  5699. See Also
  5700. --------
  5701. The corresponding attribute of the derived class of interest.
  5702. """))
  5703. add_newdoc('numpy.core.numerictypes', 'generic', ('searchsorted',
  5704. """
  5705. Not implemented (virtual attribute)
  5706. Class generic exists solely to derive numpy scalars from, and possesses,
  5707. albeit unimplemented, all the attributes of the ndarray class
  5708. so as to provide a uniform API.
  5709. See Also
  5710. --------
  5711. The corresponding attribute of the derived class of interest.
  5712. """))
  5713. add_newdoc('numpy.core.numerictypes', 'generic', ('setfield',
  5714. """
  5715. Not implemented (virtual attribute)
  5716. Class generic exists solely to derive numpy scalars from, and possesses,
  5717. albeit unimplemented, all the attributes of the ndarray class
  5718. so as to provide a uniform API.
  5719. See Also
  5720. --------
  5721. The corresponding attribute of the derived class of interest.
  5722. """))
  5723. add_newdoc('numpy.core.numerictypes', 'generic', ('setflags',
  5724. """
  5725. Not implemented (virtual attribute)
  5726. Class generic exists solely to derive numpy scalars from, and possesses,
  5727. albeit unimplemented, all the attributes of the ndarray class so as to
  5728. provide a uniform API.
  5729. See Also
  5730. --------
  5731. The corresponding attribute of the derived class of interest.
  5732. """))
  5733. add_newdoc('numpy.core.numerictypes', 'generic', ('sort',
  5734. """
  5735. Not implemented (virtual attribute)
  5736. Class generic exists solely to derive numpy scalars from, and possesses,
  5737. albeit unimplemented, all the attributes of the ndarray class
  5738. so as to provide a uniform API.
  5739. See Also
  5740. --------
  5741. The corresponding attribute of the derived class of interest.
  5742. """))
  5743. add_newdoc('numpy.core.numerictypes', 'generic', ('squeeze',
  5744. """
  5745. Not implemented (virtual attribute)
  5746. Class generic exists solely to derive numpy scalars from, and possesses,
  5747. albeit unimplemented, all the attributes of the ndarray class
  5748. so as to provide a uniform API.
  5749. See Also
  5750. --------
  5751. The corresponding attribute of the derived class of interest.
  5752. """))
  5753. add_newdoc('numpy.core.numerictypes', 'generic', ('std',
  5754. """
  5755. Not implemented (virtual attribute)
  5756. Class generic exists solely to derive numpy scalars from, and possesses,
  5757. albeit unimplemented, all the attributes of the ndarray class
  5758. so as to provide a uniform API.
  5759. See Also
  5760. --------
  5761. The corresponding attribute of the derived class of interest.
  5762. """))
  5763. add_newdoc('numpy.core.numerictypes', 'generic', ('sum',
  5764. """
  5765. Not implemented (virtual attribute)
  5766. Class generic exists solely to derive numpy scalars from, and possesses,
  5767. albeit unimplemented, all the attributes of the ndarray class
  5768. so as to provide a uniform API.
  5769. See Also
  5770. --------
  5771. The corresponding attribute of the derived class of interest.
  5772. """))
  5773. add_newdoc('numpy.core.numerictypes', 'generic', ('swapaxes',
  5774. """
  5775. Not implemented (virtual attribute)
  5776. Class generic exists solely to derive numpy scalars from, and possesses,
  5777. albeit unimplemented, all the attributes of the ndarray class
  5778. so as to provide a uniform API.
  5779. See Also
  5780. --------
  5781. The corresponding attribute of the derived class of interest.
  5782. """))
  5783. add_newdoc('numpy.core.numerictypes', 'generic', ('take',
  5784. """
  5785. Not implemented (virtual attribute)
  5786. Class generic exists solely to derive numpy scalars from, and possesses,
  5787. albeit unimplemented, all the attributes of the ndarray class
  5788. so as to provide a uniform API.
  5789. See Also
  5790. --------
  5791. The corresponding attribute of the derived class of interest.
  5792. """))
  5793. add_newdoc('numpy.core.numerictypes', 'generic', ('tofile',
  5794. """
  5795. Not implemented (virtual attribute)
  5796. Class generic exists solely to derive numpy scalars from, and possesses,
  5797. albeit unimplemented, all the attributes of the ndarray class
  5798. so as to provide a uniform API.
  5799. See Also
  5800. --------
  5801. The corresponding attribute of the derived class of interest.
  5802. """))
  5803. add_newdoc('numpy.core.numerictypes', 'generic', ('tolist',
  5804. """
  5805. Not implemented (virtual attribute)
  5806. Class generic exists solely to derive numpy scalars from, and possesses,
  5807. albeit unimplemented, all the attributes of the ndarray class
  5808. so as to provide a uniform API.
  5809. See Also
  5810. --------
  5811. The corresponding attribute of the derived class of interest.
  5812. """))
  5813. add_newdoc('numpy.core.numerictypes', 'generic', ('tostring',
  5814. """
  5815. Not implemented (virtual attribute)
  5816. Class generic exists solely to derive numpy scalars from, and possesses,
  5817. albeit unimplemented, all the attributes of the ndarray class
  5818. so as to provide a uniform API.
  5819. See Also
  5820. --------
  5821. The corresponding attribute of the derived class of interest.
  5822. """))
  5823. add_newdoc('numpy.core.numerictypes', 'generic', ('trace',
  5824. """
  5825. Not implemented (virtual attribute)
  5826. Class generic exists solely to derive numpy scalars from, and possesses,
  5827. albeit unimplemented, all the attributes of the ndarray class
  5828. so as to provide a uniform API.
  5829. See Also
  5830. --------
  5831. The corresponding attribute of the derived class of interest.
  5832. """))
  5833. add_newdoc('numpy.core.numerictypes', 'generic', ('transpose',
  5834. """
  5835. Not implemented (virtual attribute)
  5836. Class generic exists solely to derive numpy scalars from, and possesses,
  5837. albeit unimplemented, all the attributes of the ndarray class
  5838. so as to provide a uniform API.
  5839. See Also
  5840. --------
  5841. The corresponding attribute of the derived class of interest.
  5842. """))
  5843. add_newdoc('numpy.core.numerictypes', 'generic', ('var',
  5844. """
  5845. Not implemented (virtual attribute)
  5846. Class generic exists solely to derive numpy scalars from, and possesses,
  5847. albeit unimplemented, all the attributes of the ndarray class
  5848. so as to provide a uniform API.
  5849. See Also
  5850. --------
  5851. The corresponding attribute of the derived class of interest.
  5852. """))
  5853. add_newdoc('numpy.core.numerictypes', 'generic', ('view',
  5854. """
  5855. Not implemented (virtual attribute)
  5856. Class generic exists solely to derive numpy scalars from, and possesses,
  5857. albeit unimplemented, all the attributes of the ndarray class
  5858. so as to provide a uniform API.
  5859. See Also
  5860. --------
  5861. The corresponding attribute of the derived class of interest.
  5862. """))
  5863. ##############################################################################
  5864. #
  5865. # Documentation for other scalar classes
  5866. #
  5867. ##############################################################################
  5868. add_newdoc('numpy.core.numerictypes', 'bool_',
  5869. """Numpy's Boolean type. Character code: ``?``. Alias: bool8""")
  5870. add_newdoc('numpy.core.numerictypes', 'complex64',
  5871. """
  5872. Complex number type composed of two 32 bit floats. Character code: 'F'.
  5873. """)
  5874. add_newdoc('numpy.core.numerictypes', 'complex128',
  5875. """
  5876. Complex number type composed of two 64 bit floats. Character code: 'D'.
  5877. Python complex compatible.
  5878. """)
  5879. add_newdoc('numpy.core.numerictypes', 'complex256',
  5880. """
  5881. Complex number type composed of two 128-bit floats. Character code: 'G'.
  5882. """)
  5883. add_newdoc('numpy.core.numerictypes', 'float32',
  5884. """
  5885. 32-bit floating-point number. Character code 'f'. C float compatible.
  5886. """)
  5887. add_newdoc('numpy.core.numerictypes', 'float64',
  5888. """
  5889. 64-bit floating-point number. Character code 'd'. Python float compatible.
  5890. """)
  5891. add_newdoc('numpy.core.numerictypes', 'float96',
  5892. """
  5893. """)
  5894. add_newdoc('numpy.core.numerictypes', 'float128',
  5895. """
  5896. 128-bit floating-point number. Character code: 'g'. C long float
  5897. compatible.
  5898. """)
  5899. add_newdoc('numpy.core.numerictypes', 'int8',
  5900. """8-bit integer. Character code ``b``. C char compatible.""")
  5901. add_newdoc('numpy.core.numerictypes', 'int16',
  5902. """16-bit integer. Character code ``h``. C short compatible.""")
  5903. add_newdoc('numpy.core.numerictypes', 'int32',
  5904. """32-bit integer. Character code 'i'. C int compatible.""")
  5905. add_newdoc('numpy.core.numerictypes', 'int64',
  5906. """64-bit integer. Character code 'l'. Python int compatible.""")
  5907. add_newdoc('numpy.core.numerictypes', 'object_',
  5908. """Any Python object. Character code: 'O'.""")