__init__.pyi 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260
  1. import builtins
  2. import sys
  3. import datetime as dt
  4. from abc import abstractmethod
  5. from types import TracebackType
  6. from contextlib import ContextDecorator
  7. from numpy.core._internal import _ctypes
  8. from numpy.typing import (
  9. ArrayLike,
  10. DTypeLike,
  11. _Shape,
  12. _ShapeLike,
  13. _CharLike,
  14. _BoolLike,
  15. _IntLike,
  16. _FloatLike,
  17. _ComplexLike,
  18. _NumberLike,
  19. _SupportsDType,
  20. _VoidDTypeLike,
  21. NBitBase,
  22. _64Bit,
  23. _32Bit,
  24. _16Bit,
  25. _8Bit,
  26. )
  27. from numpy.typing._callable import (
  28. _BoolOp,
  29. _BoolBitOp,
  30. _BoolSub,
  31. _BoolTrueDiv,
  32. _BoolMod,
  33. _BoolDivMod,
  34. _TD64Div,
  35. _IntTrueDiv,
  36. _UnsignedIntOp,
  37. _UnsignedIntBitOp,
  38. _UnsignedIntMod,
  39. _UnsignedIntDivMod,
  40. _SignedIntOp,
  41. _SignedIntBitOp,
  42. _SignedIntMod,
  43. _SignedIntDivMod,
  44. _FloatOp,
  45. _FloatMod,
  46. _FloatDivMod,
  47. _ComplexOp,
  48. _NumberOp,
  49. )
  50. from typing import (
  51. Any,
  52. ByteString,
  53. Callable,
  54. Container,
  55. Callable,
  56. Dict,
  57. Generic,
  58. IO,
  59. Iterable,
  60. List,
  61. Mapping,
  62. Optional,
  63. overload,
  64. Sequence,
  65. Sized,
  66. SupportsComplex,
  67. SupportsFloat,
  68. SupportsInt,
  69. Text,
  70. Tuple,
  71. Type,
  72. TypeVar,
  73. Union,
  74. )
  75. if sys.version_info >= (3, 8):
  76. from typing import Literal, Protocol, SupportsIndex, Final
  77. else:
  78. from typing_extensions import Literal, Protocol, Final
  79. class SupportsIndex(Protocol):
  80. def __index__(self) -> int: ...
  81. # Ensures that the stubs are picked up
  82. from numpy import (
  83. char as char,
  84. ctypeslib as ctypeslib,
  85. emath as emath,
  86. fft as fft,
  87. lib as lib,
  88. linalg as linalg,
  89. ma as ma,
  90. matrixlib as matrixlib,
  91. polynomial as polynomial,
  92. random as random,
  93. rec as rec,
  94. testing as testing,
  95. version as version,
  96. )
  97. from numpy.core.function_base import (
  98. linspace as linspace,
  99. logspace as logspace,
  100. geomspace as geomspace,
  101. )
  102. from numpy.core.fromnumeric import (
  103. take as take,
  104. reshape as reshape,
  105. choose as choose,
  106. repeat as repeat,
  107. put as put,
  108. swapaxes as swapaxes,
  109. transpose as transpose,
  110. partition as partition,
  111. argpartition as argpartition,
  112. sort as sort,
  113. argsort as argsort,
  114. argmax as argmax,
  115. argmin as argmin,
  116. searchsorted as searchsorted,
  117. resize as resize,
  118. squeeze as squeeze,
  119. diagonal as diagonal,
  120. trace as trace,
  121. ravel as ravel,
  122. nonzero as nonzero,
  123. shape as shape,
  124. compress as compress,
  125. clip as clip,
  126. sum as sum,
  127. all as all,
  128. any as any,
  129. cumsum as cumsum,
  130. ptp as ptp,
  131. amax as amax,
  132. amin as amin,
  133. prod as prod,
  134. cumprod as cumprod,
  135. ndim as ndim,
  136. size as size,
  137. around as around,
  138. mean as mean,
  139. std as std,
  140. var as var,
  141. )
  142. from numpy.core._asarray import (
  143. asarray as asarray,
  144. asanyarray as asanyarray,
  145. ascontiguousarray as ascontiguousarray,
  146. asfortranarray as asfortranarray,
  147. require as require,
  148. )
  149. from numpy.core._type_aliases import (
  150. sctypes as sctypes,
  151. sctypeDict as sctypeDict,
  152. )
  153. from numpy.core._ufunc_config import (
  154. seterr as seterr,
  155. geterr as geterr,
  156. setbufsize as setbufsize,
  157. getbufsize as getbufsize,
  158. seterrcall as seterrcall,
  159. geterrcall as geterrcall,
  160. _SupportsWrite,
  161. _ErrKind,
  162. _ErrFunc,
  163. _ErrDictOptional,
  164. )
  165. from numpy.core.numeric import (
  166. zeros_like as zeros_like,
  167. ones as ones,
  168. ones_like as ones_like,
  169. empty_like as empty_like,
  170. full as full,
  171. full_like as full_like,
  172. count_nonzero as count_nonzero,
  173. isfortran as isfortran,
  174. argwhere as argwhere,
  175. flatnonzero as flatnonzero,
  176. correlate as correlate,
  177. convolve as convolve,
  178. outer as outer,
  179. tensordot as tensordot,
  180. roll as roll,
  181. rollaxis as rollaxis,
  182. moveaxis as moveaxis,
  183. cross as cross,
  184. indices as indices,
  185. fromfunction as fromfunction,
  186. isscalar as isscalar,
  187. binary_repr as binary_repr,
  188. base_repr as base_repr,
  189. identity as identity,
  190. allclose as allclose,
  191. isclose as isclose,
  192. array_equal as array_equal,
  193. array_equiv as array_equiv,
  194. )
  195. from numpy.core.numerictypes import (
  196. maximum_sctype as maximum_sctype,
  197. issctype as issctype,
  198. obj2sctype as obj2sctype,
  199. issubclass_ as issubclass_,
  200. issubsctype as issubsctype,
  201. issubdtype as issubdtype,
  202. sctype2char as sctype2char,
  203. find_common_type as find_common_type,
  204. )
  205. from numpy.core.shape_base import (
  206. atleast_1d as atleast_1d,
  207. atleast_2d as atleast_2d,
  208. atleast_3d as atleast_3d,
  209. block as block,
  210. hstack as hstack,
  211. stack as stack,
  212. vstack as vstack,
  213. )
  214. __all__: List[str]
  215. __path__: List[str]
  216. __version__: str
  217. DataSource: Any
  218. MachAr: Any
  219. ScalarType: Any
  220. angle: Any
  221. append: Any
  222. apply_along_axis: Any
  223. apply_over_axes: Any
  224. arange: Any
  225. array2string: Any
  226. array_repr: Any
  227. array_split: Any
  228. array_str: Any
  229. asarray_chkfinite: Any
  230. asfarray: Any
  231. asmatrix: Any
  232. asscalar: Any
  233. average: Any
  234. bartlett: Any
  235. bincount: Any
  236. bitwise_not: Any
  237. blackman: Any
  238. bmat: Any
  239. bool8: Any
  240. broadcast: Any
  241. broadcast_arrays: Any
  242. broadcast_to: Any
  243. busday_count: Any
  244. busday_offset: Any
  245. busdaycalendar: Any
  246. byte: Any
  247. byte_bounds: Any
  248. bytes0: Any
  249. c_: Any
  250. can_cast: Any
  251. cast: Any
  252. cdouble: Any
  253. cfloat: Any
  254. chararray: Any
  255. clongdouble: Any
  256. clongfloat: Any
  257. column_stack: Any
  258. common_type: Any
  259. compare_chararrays: Any
  260. complex256: Any
  261. complex_: Any
  262. concatenate: Any
  263. conj: Any
  264. copy: Any
  265. copyto: Any
  266. corrcoef: Any
  267. cov: Any
  268. csingle: Any
  269. cumproduct: Any
  270. datetime_as_string: Any
  271. datetime_data: Any
  272. delete: Any
  273. deprecate: Any
  274. deprecate_with_doc: Any
  275. diag: Any
  276. diag_indices: Any
  277. diag_indices_from: Any
  278. diagflat: Any
  279. diff: Any
  280. digitize: Any
  281. disp: Any
  282. divide: Any
  283. dot: Any
  284. double: Any
  285. dsplit: Any
  286. dstack: Any
  287. ediff1d: Any
  288. einsum: Any
  289. einsum_path: Any
  290. expand_dims: Any
  291. extract: Any
  292. eye: Any
  293. fill_diagonal: Any
  294. finfo: Any
  295. fix: Any
  296. flip: Any
  297. fliplr: Any
  298. flipud: Any
  299. float128: Any
  300. float_: Any
  301. format_float_positional: Any
  302. format_float_scientific: Any
  303. format_parser: Any
  304. frombuffer: Any
  305. fromfile: Any
  306. fromiter: Any
  307. frompyfunc: Any
  308. fromregex: Any
  309. fromstring: Any
  310. genfromtxt: Any
  311. get_include: Any
  312. get_printoptions: Any
  313. geterrobj: Any
  314. gradient: Any
  315. half: Any
  316. hamming: Any
  317. hanning: Any
  318. histogram: Any
  319. histogram2d: Any
  320. histogram_bin_edges: Any
  321. histogramdd: Any
  322. hsplit: Any
  323. i0: Any
  324. iinfo: Any
  325. imag: Any
  326. in1d: Any
  327. index_exp: Any
  328. info: Any
  329. inner: Any
  330. insert: Any
  331. int0: Any
  332. int_: Any
  333. intc: Any
  334. interp: Any
  335. intersect1d: Any
  336. intp: Any
  337. is_busday: Any
  338. iscomplex: Any
  339. iscomplexobj: Any
  340. isin: Any
  341. isneginf: Any
  342. isposinf: Any
  343. isreal: Any
  344. isrealobj: Any
  345. iterable: Any
  346. ix_: Any
  347. kaiser: Any
  348. kron: Any
  349. lexsort: Any
  350. load: Any
  351. loads: Any
  352. loadtxt: Any
  353. longcomplex: Any
  354. longdouble: Any
  355. longfloat: Any
  356. longlong: Any
  357. lookfor: Any
  358. mafromtxt: Any
  359. mask_indices: Any
  360. mat: Any
  361. matrix: Any
  362. max: Any
  363. may_share_memory: Any
  364. median: Any
  365. memmap: Any
  366. meshgrid: Any
  367. mgrid: Any
  368. min: Any
  369. min_scalar_type: Any
  370. mintypecode: Any
  371. mod: Any
  372. msort: Any
  373. nan_to_num: Any
  374. nanargmax: Any
  375. nanargmin: Any
  376. nancumprod: Any
  377. nancumsum: Any
  378. nanmax: Any
  379. nanmean: Any
  380. nanmedian: Any
  381. nanmin: Any
  382. nanpercentile: Any
  383. nanprod: Any
  384. nanquantile: Any
  385. nanstd: Any
  386. nansum: Any
  387. nanvar: Any
  388. nbytes: Any
  389. ndenumerate: Any
  390. ndfromtxt: Any
  391. ndindex: Any
  392. nditer: Any
  393. nested_iters: Any
  394. newaxis: Any
  395. numarray: Any
  396. object0: Any
  397. ogrid: Any
  398. packbits: Any
  399. pad: Any
  400. percentile: Any
  401. piecewise: Any
  402. place: Any
  403. poly: Any
  404. poly1d: Any
  405. polyadd: Any
  406. polyder: Any
  407. polydiv: Any
  408. polyfit: Any
  409. polyint: Any
  410. polymul: Any
  411. polysub: Any
  412. polyval: Any
  413. printoptions: Any
  414. product: Any
  415. promote_types: Any
  416. put_along_axis: Any
  417. putmask: Any
  418. quantile: Any
  419. r_: Any
  420. ravel_multi_index: Any
  421. real: Any
  422. real_if_close: Any
  423. recarray: Any
  424. recfromcsv: Any
  425. recfromtxt: Any
  426. record: Any
  427. result_type: Any
  428. roots: Any
  429. rot90: Any
  430. round: Any
  431. round_: Any
  432. row_stack: Any
  433. s_: Any
  434. save: Any
  435. savetxt: Any
  436. savez: Any
  437. savez_compressed: Any
  438. select: Any
  439. set_printoptions: Any
  440. set_string_function: Any
  441. setdiff1d: Any
  442. seterrobj: Any
  443. setxor1d: Any
  444. shares_memory: Any
  445. short: Any
  446. show_config: Any
  447. sinc: Any
  448. single: Any
  449. singlecomplex: Any
  450. sort_complex: Any
  451. source: Any
  452. split: Any
  453. string_: Any
  454. take_along_axis: Any
  455. tile: Any
  456. trapz: Any
  457. tri: Any
  458. tril: Any
  459. tril_indices: Any
  460. tril_indices_from: Any
  461. trim_zeros: Any
  462. triu: Any
  463. triu_indices: Any
  464. triu_indices_from: Any
  465. typeDict: Any
  466. typecodes: Any
  467. typename: Any
  468. ubyte: Any
  469. uint: Any
  470. uint0: Any
  471. uintc: Any
  472. uintp: Any
  473. ulonglong: Any
  474. union1d: Any
  475. unique: Any
  476. unpackbits: Any
  477. unravel_index: Any
  478. unwrap: Any
  479. ushort: Any
  480. vander: Any
  481. vdot: Any
  482. vectorize: Any
  483. void0: Any
  484. vsplit: Any
  485. where: Any
  486. who: Any
  487. _NdArraySubClass = TypeVar("_NdArraySubClass", bound=ndarray)
  488. _DTypeScalar = TypeVar("_DTypeScalar", bound=generic)
  489. _ByteOrder = Literal["S", "<", ">", "=", "|", "L", "B", "N", "I"]
  490. class dtype(Generic[_DTypeScalar]):
  491. names: Optional[Tuple[str, ...]]
  492. # Overload for subclass of generic
  493. @overload
  494. def __new__(
  495. cls,
  496. dtype: Type[_DTypeScalar],
  497. align: bool = ...,
  498. copy: bool = ...,
  499. ) -> dtype[_DTypeScalar]: ...
  500. # Overloads for string aliases, Python types, and some assorted
  501. # other special cases. Order is sometimes important because of the
  502. # subtype relationships
  503. #
  504. # bool < int < float < complex
  505. #
  506. # so we have to make sure the overloads for the narrowest type is
  507. # first.
  508. @overload
  509. def __new__(
  510. cls,
  511. dtype: Union[
  512. Type[bool],
  513. Literal[
  514. "?",
  515. "=?",
  516. "<?",
  517. ">?",
  518. "bool",
  519. "bool_",
  520. ],
  521. ],
  522. align: bool = ...,
  523. copy: bool = ...,
  524. ) -> dtype[bool_]: ...
  525. @overload
  526. def __new__(
  527. cls,
  528. dtype: Literal[
  529. "uint8",
  530. "u1",
  531. "=u1",
  532. "<u1",
  533. ">u1",
  534. ],
  535. align: bool = ...,
  536. copy: bool = ...,
  537. ) -> dtype[uint8]: ...
  538. @overload
  539. def __new__(
  540. cls,
  541. dtype: Literal[
  542. "uint16",
  543. "u2",
  544. "=u2",
  545. "<u2",
  546. ">u2",
  547. ],
  548. align: bool = ...,
  549. copy: bool = ...,
  550. ) -> dtype[uint16]: ...
  551. @overload
  552. def __new__(
  553. cls,
  554. dtype: Literal[
  555. "uint32",
  556. "u4",
  557. "=u4",
  558. "<u4",
  559. ">u4",
  560. ],
  561. align: bool = ...,
  562. copy: bool = ...,
  563. ) -> dtype[uint32]: ...
  564. @overload
  565. def __new__(
  566. cls,
  567. dtype: Literal[
  568. "uint64",
  569. "u8",
  570. "=u8",
  571. "<u8",
  572. ">u8",
  573. ],
  574. align: bool = ...,
  575. copy: bool = ...,
  576. ) -> dtype[uint64]: ...
  577. @overload
  578. def __new__(
  579. cls,
  580. dtype: Literal[
  581. "int8",
  582. "i1",
  583. "=i1",
  584. "<i1",
  585. ">i1",
  586. ],
  587. align: bool = ...,
  588. copy: bool = ...,
  589. ) -> dtype[int8]: ...
  590. @overload
  591. def __new__(
  592. cls,
  593. dtype: Literal[
  594. "int16",
  595. "i2",
  596. "=i2",
  597. "<i2",
  598. ">i2",
  599. ],
  600. align: bool = ...,
  601. copy: bool = ...,
  602. ) -> dtype[int16]: ...
  603. @overload
  604. def __new__(
  605. cls,
  606. dtype: Literal[
  607. "int32",
  608. "i4",
  609. "=i4",
  610. "<i4",
  611. ">i4",
  612. ],
  613. align: bool = ...,
  614. copy: bool = ...,
  615. ) -> dtype[int32]: ...
  616. @overload
  617. def __new__(
  618. cls,
  619. dtype: Literal[
  620. "int64",
  621. "i8",
  622. "=i8",
  623. "<i8",
  624. ">i8",
  625. ],
  626. align: bool = ...,
  627. copy: bool = ...,
  628. ) -> dtype[int64]: ...
  629. # "int"/int resolve to int_, which is system dependent and as of
  630. # now untyped. Long-term we'll do something fancier here.
  631. @overload
  632. def __new__(
  633. cls,
  634. dtype: Union[Type[int], Literal["int"]],
  635. align: bool = ...,
  636. copy: bool = ...,
  637. ) -> dtype: ...
  638. @overload
  639. def __new__(
  640. cls,
  641. dtype: Literal[
  642. "float16",
  643. "f4",
  644. "=f4",
  645. "<f4",
  646. ">f4",
  647. "e",
  648. "=e",
  649. "<e",
  650. ">e",
  651. "half",
  652. ],
  653. align: bool = ...,
  654. copy: bool = ...,
  655. ) -> dtype[float16]: ...
  656. @overload
  657. def __new__(
  658. cls,
  659. dtype: Literal[
  660. "float32",
  661. "f4",
  662. "=f4",
  663. "<f4",
  664. ">f4",
  665. "f",
  666. "=f",
  667. "<f",
  668. ">f",
  669. "single",
  670. ],
  671. align: bool = ...,
  672. copy: bool = ...,
  673. ) -> dtype[float32]: ...
  674. @overload
  675. def __new__(
  676. cls,
  677. dtype: Union[
  678. None,
  679. Type[float],
  680. Literal[
  681. "float64",
  682. "f8",
  683. "=f8",
  684. "<f8",
  685. ">f8",
  686. "d",
  687. "<d",
  688. ">d",
  689. "float",
  690. "double",
  691. "float_",
  692. ],
  693. ],
  694. align: bool = ...,
  695. copy: bool = ...,
  696. ) -> dtype[float64]: ...
  697. @overload
  698. def __new__(
  699. cls,
  700. dtype: Literal[
  701. "complex64",
  702. "c8",
  703. "=c8",
  704. "<c8",
  705. ">c8",
  706. "F",
  707. "=F",
  708. "<F",
  709. ">F",
  710. ],
  711. align: bool = ...,
  712. copy: bool = ...,
  713. ) -> dtype[complex64]: ...
  714. @overload
  715. def __new__(
  716. cls,
  717. dtype: Union[
  718. Type[complex],
  719. Literal[
  720. "complex128",
  721. "c16",
  722. "=c16",
  723. "<c16",
  724. ">c16",
  725. "D",
  726. "=D",
  727. "<D",
  728. ">D",
  729. ],
  730. ],
  731. align: bool = ...,
  732. copy: bool = ...,
  733. ) -> dtype[complex128]: ...
  734. @overload
  735. def __new__(
  736. cls,
  737. dtype: Union[
  738. Type[bytes],
  739. Literal[
  740. "S",
  741. "=S",
  742. "<S",
  743. ">S",
  744. "bytes",
  745. "bytes_",
  746. "bytes0",
  747. ],
  748. ],
  749. align: bool = ...,
  750. copy: bool = ...,
  751. ) -> dtype[bytes_]: ...
  752. @overload
  753. def __new__(
  754. cls,
  755. dtype: Union[
  756. Type[str],
  757. Literal[
  758. "U",
  759. "=U",
  760. # <U and >U intentionally not included; they are not
  761. # the same dtype and which one dtype("U") translates
  762. # to is platform-dependent.
  763. "str",
  764. "str_",
  765. "str0",
  766. ],
  767. ],
  768. align: bool = ...,
  769. copy: bool = ...,
  770. ) -> dtype[str_]: ...
  771. # dtype of a dtype is the same dtype
  772. @overload
  773. def __new__(
  774. cls,
  775. dtype: dtype[_DTypeScalar],
  776. align: bool = ...,
  777. copy: bool = ...,
  778. ) -> dtype[_DTypeScalar]: ...
  779. # TODO: handle _SupportsDType better
  780. @overload
  781. def __new__(
  782. cls,
  783. dtype: _SupportsDType,
  784. align: bool = ...,
  785. copy: bool = ...,
  786. ) -> dtype[Any]: ...
  787. # Handle strings that can't be expressed as literals; i.e. s1, s2, ...
  788. @overload
  789. def __new__(
  790. cls,
  791. dtype: str,
  792. align: bool = ...,
  793. copy: bool = ...,
  794. ) -> dtype[Any]: ...
  795. # Catchall overload
  796. @overload
  797. def __new__(
  798. cls,
  799. dtype: _VoidDTypeLike,
  800. align: bool = ...,
  801. copy: bool = ...,
  802. ) -> dtype[void]: ...
  803. @overload
  804. def __getitem__(self: dtype[void], key: List[str]) -> dtype[void]: ...
  805. @overload
  806. def __getitem__(self: dtype[void], key: Union[str, int]) -> dtype[Any]: ...
  807. # NOTE: In the future 1-based multiplications will also yield `void` dtypes
  808. @overload
  809. def __mul__(self, value: Literal[0]) -> None: ... # type: ignore[misc]
  810. @overload
  811. def __mul__(self, value: Literal[1]) -> dtype[_DTypeScalar]: ...
  812. @overload
  813. def __mul__(self, value: int) -> dtype[void]: ...
  814. # NOTE: `__rmul__` seems to be broken when used in combination with
  815. # literals as of mypy 0.800. Set the return-type to `Any` for now.
  816. def __rmul__(self, value: int) -> Any: ...
  817. def __eq__(self, other: DTypeLike) -> bool: ...
  818. def __ne__(self, other: DTypeLike) -> bool: ...
  819. def __gt__(self, other: DTypeLike) -> bool: ...
  820. def __ge__(self, other: DTypeLike) -> bool: ...
  821. def __lt__(self, other: DTypeLike) -> bool: ...
  822. def __le__(self, other: DTypeLike) -> bool: ...
  823. @property
  824. def alignment(self) -> int: ...
  825. @property
  826. def base(self) -> dtype: ...
  827. @property
  828. def byteorder(self) -> str: ...
  829. @property
  830. def char(self) -> str: ...
  831. @property
  832. def descr(self) -> List[Union[Tuple[str, str], Tuple[str, str, _Shape]]]: ...
  833. @property
  834. def fields(
  835. self,
  836. ) -> Optional[Mapping[str, Union[Tuple[dtype, int], Tuple[dtype, int, Any]]]]: ...
  837. @property
  838. def flags(self) -> int: ...
  839. @property
  840. def hasobject(self) -> bool: ...
  841. @property
  842. def isbuiltin(self) -> int: ...
  843. @property
  844. def isnative(self) -> bool: ...
  845. @property
  846. def isalignedstruct(self) -> bool: ...
  847. @property
  848. def itemsize(self) -> int: ...
  849. @property
  850. def kind(self) -> str: ...
  851. @property
  852. def metadata(self) -> Optional[Mapping[str, Any]]: ...
  853. @property
  854. def name(self) -> str: ...
  855. @property
  856. def names(self) -> Optional[Tuple[str, ...]]: ...
  857. @property
  858. def num(self) -> int: ...
  859. @property
  860. def shape(self) -> _Shape: ...
  861. @property
  862. def ndim(self) -> int: ...
  863. @property
  864. def subdtype(self) -> Optional[Tuple[dtype, _Shape]]: ...
  865. def newbyteorder(self, __new_order: _ByteOrder = ...) -> dtype: ...
  866. # Leave str and type for end to avoid having to use `builtins.str`
  867. # everywhere. See https://github.com/python/mypy/issues/3775
  868. @property
  869. def str(self) -> builtins.str: ...
  870. @property
  871. def type(self) -> Type[generic]: ...
  872. _DType = dtype # to avoid name conflicts with ndarray.dtype
  873. class _flagsobj:
  874. aligned: bool
  875. updateifcopy: bool
  876. writeable: bool
  877. writebackifcopy: bool
  878. @property
  879. def behaved(self) -> bool: ...
  880. @property
  881. def c_contiguous(self) -> bool: ...
  882. @property
  883. def carray(self) -> bool: ...
  884. @property
  885. def contiguous(self) -> bool: ...
  886. @property
  887. def f_contiguous(self) -> bool: ...
  888. @property
  889. def farray(self) -> bool: ...
  890. @property
  891. def fnc(self) -> bool: ...
  892. @property
  893. def forc(self) -> bool: ...
  894. @property
  895. def fortran(self) -> bool: ...
  896. @property
  897. def num(self) -> int: ...
  898. @property
  899. def owndata(self) -> bool: ...
  900. def __getitem__(self, key: str) -> bool: ...
  901. def __setitem__(self, key: str, value: bool) -> None: ...
  902. _ArrayLikeInt = Union[
  903. int,
  904. integer,
  905. Sequence[Union[int, integer]],
  906. Sequence[Sequence[Any]], # TODO: wait for support for recursive types
  907. ndarray
  908. ]
  909. _FlatIterSelf = TypeVar("_FlatIterSelf", bound=flatiter)
  910. class flatiter(Generic[_ArraySelf]):
  911. @property
  912. def base(self) -> _ArraySelf: ...
  913. @property
  914. def coords(self) -> _Shape: ...
  915. @property
  916. def index(self) -> int: ...
  917. def copy(self) -> _ArraySelf: ...
  918. def __iter__(self: _FlatIterSelf) -> _FlatIterSelf: ...
  919. def __next__(self) -> generic: ...
  920. def __len__(self) -> int: ...
  921. @overload
  922. def __getitem__(self, key: Union[int, integer]) -> generic: ...
  923. @overload
  924. def __getitem__(
  925. self, key: Union[_ArrayLikeInt, slice, ellipsis],
  926. ) -> _ArraySelf: ...
  927. def __array__(self, __dtype: DTypeLike = ...) -> ndarray: ...
  928. _OrderKACF = Optional[Literal["K", "A", "C", "F"]]
  929. _OrderACF = Optional[Literal["A", "C", "F"]]
  930. _OrderCF = Optional[Literal["C", "F"]]
  931. _ModeKind = Literal["raise", "wrap", "clip"]
  932. _PartitionKind = Literal["introselect"]
  933. _SortKind = Literal["quicksort", "mergesort", "heapsort", "stable"]
  934. _SortSide = Literal["left", "right"]
  935. _ArrayLikeBool = Union[_BoolLike, Sequence[_BoolLike], ndarray]
  936. _ArrayLikeIntOrBool = Union[
  937. _IntLike,
  938. _BoolLike,
  939. ndarray,
  940. Sequence[_IntLike],
  941. Sequence[_BoolLike],
  942. Sequence[Sequence[Any]], # TODO: wait for support for recursive types
  943. ]
  944. _ArraySelf = TypeVar("_ArraySelf", bound=_ArrayOrScalarCommon)
  945. class _ArrayOrScalarCommon:
  946. @property
  947. def T(self: _ArraySelf) -> _ArraySelf: ...
  948. @property
  949. def data(self) -> memoryview: ...
  950. @property
  951. def flags(self) -> _flagsobj: ...
  952. @property
  953. def itemsize(self) -> int: ...
  954. @property
  955. def nbytes(self) -> int: ...
  956. def __array__(self, __dtype: DTypeLike = ...) -> ndarray: ...
  957. def __bool__(self) -> bool: ...
  958. def __bytes__(self) -> bytes: ...
  959. def __str__(self) -> str: ...
  960. def __repr__(self) -> str: ...
  961. def __copy__(self: _ArraySelf) -> _ArraySelf: ...
  962. def __deepcopy__(self: _ArraySelf, __memo: Optional[dict] = ...) -> _ArraySelf: ...
  963. def __lt__(self, other): ...
  964. def __le__(self, other): ...
  965. def __eq__(self, other): ...
  966. def __ne__(self, other): ...
  967. def __gt__(self, other): ...
  968. def __ge__(self, other): ...
  969. def astype(
  970. self: _ArraySelf,
  971. dtype: DTypeLike,
  972. order: _OrderKACF = ...,
  973. casting: _Casting = ...,
  974. subok: bool = ...,
  975. copy: bool = ...,
  976. ) -> _ArraySelf: ...
  977. def copy(self: _ArraySelf, order: _OrderKACF = ...) -> _ArraySelf: ...
  978. def dump(self, file: str) -> None: ...
  979. def dumps(self) -> bytes: ...
  980. def flatten(self, order: _OrderKACF = ...) -> ndarray: ...
  981. def getfield(
  982. self: _ArraySelf, dtype: DTypeLike, offset: int = ...
  983. ) -> _ArraySelf: ...
  984. def ravel(self, order: _OrderKACF = ...) -> ndarray: ...
  985. @overload
  986. def reshape(
  987. self, __shape: _ShapeLike, *, order: _OrderACF = ...
  988. ) -> ndarray: ...
  989. @overload
  990. def reshape(
  991. self, *shape: SupportsIndex, order: _OrderACF = ...
  992. ) -> ndarray: ...
  993. def tobytes(self, order: _OrderKACF = ...) -> bytes: ...
  994. # NOTE: `tostring()` is deprecated and therefore excluded
  995. # def tostring(self, order=...): ...
  996. def tofile(
  997. self, fid: Union[IO[bytes], str], sep: str = ..., format: str = ...
  998. ) -> None: ...
  999. # generics and 0d arrays return builtin scalars
  1000. def tolist(self) -> Any: ...
  1001. @overload
  1002. def view(self, type: Type[_NdArraySubClass]) -> _NdArraySubClass: ...
  1003. @overload
  1004. def view(self: _ArraySelf, dtype: DTypeLike = ...) -> _ArraySelf: ...
  1005. @overload
  1006. def view(
  1007. self, dtype: DTypeLike, type: Type[_NdArraySubClass]
  1008. ) -> _NdArraySubClass: ...
  1009. # TODO: Add proper signatures
  1010. def __getitem__(self, key) -> Any: ...
  1011. @property
  1012. def __array_interface__(self): ...
  1013. @property
  1014. def __array_priority__(self): ...
  1015. @property
  1016. def __array_struct__(self): ...
  1017. def __array_wrap__(array, context=...): ...
  1018. def __setstate__(self, __state): ...
  1019. # a `bool_` is returned when `keepdims=True` and `self` is a 0d array
  1020. @overload
  1021. def all(
  1022. self,
  1023. axis: None = ...,
  1024. out: None = ...,
  1025. keepdims: Literal[False] = ...,
  1026. ) -> bool_: ...
  1027. @overload
  1028. def all(
  1029. self,
  1030. axis: Optional[_ShapeLike] = ...,
  1031. out: None = ...,
  1032. keepdims: bool = ...,
  1033. ) -> Any: ...
  1034. @overload
  1035. def all(
  1036. self,
  1037. axis: Optional[_ShapeLike] = ...,
  1038. out: _NdArraySubClass = ...,
  1039. keepdims: bool = ...,
  1040. ) -> _NdArraySubClass: ...
  1041. @overload
  1042. def any(
  1043. self,
  1044. axis: None = ...,
  1045. out: None = ...,
  1046. keepdims: Literal[False] = ...,
  1047. ) -> bool_: ...
  1048. @overload
  1049. def any(
  1050. self,
  1051. axis: Optional[_ShapeLike] = ...,
  1052. out: None = ...,
  1053. keepdims: bool = ...,
  1054. ) -> Any: ...
  1055. @overload
  1056. def any(
  1057. self,
  1058. axis: Optional[_ShapeLike] = ...,
  1059. out: _NdArraySubClass = ...,
  1060. keepdims: bool = ...,
  1061. ) -> _NdArraySubClass: ...
  1062. @overload
  1063. def argmax(
  1064. self,
  1065. axis: None = ...,
  1066. out: None = ...,
  1067. ) -> signedinteger[Any]: ...
  1068. @overload
  1069. def argmax(
  1070. self,
  1071. axis: _ShapeLike = ...,
  1072. out: None = ...,
  1073. ) -> Any: ...
  1074. @overload
  1075. def argmax(
  1076. self,
  1077. axis: Optional[_ShapeLike] = ...,
  1078. out: _NdArraySubClass = ...,
  1079. ) -> _NdArraySubClass: ...
  1080. @overload
  1081. def argmin(
  1082. self,
  1083. axis: None = ...,
  1084. out: None = ...,
  1085. ) -> signedinteger[Any]: ...
  1086. @overload
  1087. def argmin(
  1088. self,
  1089. axis: _ShapeLike = ...,
  1090. out: None = ...,
  1091. ) -> Any: ...
  1092. @overload
  1093. def argmin(
  1094. self,
  1095. axis: Optional[_ShapeLike] = ...,
  1096. out: _NdArraySubClass = ...,
  1097. ) -> _NdArraySubClass: ...
  1098. def argsort(
  1099. self,
  1100. axis: Optional[SupportsIndex] = ...,
  1101. kind: Optional[_SortKind] = ...,
  1102. order: Union[None, str, Sequence[str]] = ...,
  1103. ) -> ndarray: ...
  1104. @overload
  1105. def choose(
  1106. self,
  1107. choices: ArrayLike,
  1108. out: None = ...,
  1109. mode: _ModeKind = ...,
  1110. ) -> ndarray: ...
  1111. @overload
  1112. def choose(
  1113. self,
  1114. choices: ArrayLike,
  1115. out: _NdArraySubClass = ...,
  1116. mode: _ModeKind = ...,
  1117. ) -> _NdArraySubClass: ...
  1118. @overload
  1119. def clip(
  1120. self,
  1121. min: ArrayLike = ...,
  1122. max: Optional[ArrayLike] = ...,
  1123. out: None = ...,
  1124. **kwargs: Any,
  1125. ) -> Any: ...
  1126. @overload
  1127. def clip(
  1128. self,
  1129. min: None = ...,
  1130. max: ArrayLike = ...,
  1131. out: None = ...,
  1132. **kwargs: Any,
  1133. ) -> Any: ...
  1134. @overload
  1135. def clip(
  1136. self,
  1137. min: ArrayLike = ...,
  1138. max: Optional[ArrayLike] = ...,
  1139. out: _NdArraySubClass = ...,
  1140. **kwargs: Any,
  1141. ) -> _NdArraySubClass: ...
  1142. @overload
  1143. def clip(
  1144. self,
  1145. min: None = ...,
  1146. max: ArrayLike = ...,
  1147. out: _NdArraySubClass = ...,
  1148. **kwargs: Any,
  1149. ) -> _NdArraySubClass: ...
  1150. @overload
  1151. def compress(
  1152. self,
  1153. a: ArrayLike,
  1154. axis: Optional[SupportsIndex] = ...,
  1155. out: None = ...,
  1156. ) -> ndarray: ...
  1157. @overload
  1158. def compress(
  1159. self,
  1160. a: ArrayLike,
  1161. axis: Optional[SupportsIndex] = ...,
  1162. out: _NdArraySubClass = ...,
  1163. ) -> _NdArraySubClass: ...
  1164. def conj(self: _ArraySelf) -> _ArraySelf: ...
  1165. def conjugate(self: _ArraySelf) -> _ArraySelf: ...
  1166. @overload
  1167. def cumprod(
  1168. self,
  1169. axis: Optional[SupportsIndex] = ...,
  1170. dtype: DTypeLike = ...,
  1171. out: None = ...,
  1172. ) -> ndarray: ...
  1173. @overload
  1174. def cumprod(
  1175. self,
  1176. axis: Optional[SupportsIndex] = ...,
  1177. dtype: DTypeLike = ...,
  1178. out: _NdArraySubClass = ...,
  1179. ) -> _NdArraySubClass: ...
  1180. @overload
  1181. def cumsum(
  1182. self,
  1183. axis: Optional[SupportsIndex] = ...,
  1184. dtype: DTypeLike = ...,
  1185. out: None = ...,
  1186. ) -> ndarray: ...
  1187. @overload
  1188. def cumsum(
  1189. self,
  1190. axis: Optional[SupportsIndex] = ...,
  1191. dtype: DTypeLike = ...,
  1192. out: _NdArraySubClass = ...,
  1193. ) -> _NdArraySubClass: ...
  1194. @overload
  1195. def max(
  1196. self,
  1197. axis: Optional[_ShapeLike] = ...,
  1198. out: None = ...,
  1199. keepdims: bool = ...,
  1200. initial: _NumberLike = ...,
  1201. where: _ArrayLikeBool = ...,
  1202. ) -> Any: ...
  1203. @overload
  1204. def max(
  1205. self,
  1206. axis: Optional[_ShapeLike] = ...,
  1207. out: _NdArraySubClass = ...,
  1208. keepdims: bool = ...,
  1209. initial: _NumberLike = ...,
  1210. where: _ArrayLikeBool = ...,
  1211. ) -> _NdArraySubClass: ...
  1212. @overload
  1213. def mean(
  1214. self,
  1215. axis: Optional[_ShapeLike] = ...,
  1216. dtype: DTypeLike = ...,
  1217. out: None = ...,
  1218. keepdims: bool = ...,
  1219. ) -> Any: ...
  1220. @overload
  1221. def mean(
  1222. self,
  1223. axis: Optional[_ShapeLike] = ...,
  1224. dtype: DTypeLike = ...,
  1225. out: _NdArraySubClass = ...,
  1226. keepdims: bool = ...,
  1227. ) -> _NdArraySubClass: ...
  1228. @overload
  1229. def min(
  1230. self,
  1231. axis: Optional[_ShapeLike] = ...,
  1232. out: None = ...,
  1233. keepdims: bool = ...,
  1234. initial: _NumberLike = ...,
  1235. where: _ArrayLikeBool = ...,
  1236. ) -> Any: ...
  1237. @overload
  1238. def min(
  1239. self,
  1240. axis: Optional[_ShapeLike] = ...,
  1241. out: _NdArraySubClass = ...,
  1242. keepdims: bool = ...,
  1243. initial: _NumberLike = ...,
  1244. where: _ArrayLikeBool = ...,
  1245. ) -> _NdArraySubClass: ...
  1246. def newbyteorder(
  1247. self: _ArraySelf,
  1248. __new_order: _ByteOrder = ...,
  1249. ) -> _ArraySelf: ...
  1250. @overload
  1251. def prod(
  1252. self,
  1253. axis: Optional[_ShapeLike] = ...,
  1254. dtype: DTypeLike = ...,
  1255. out: None = ...,
  1256. keepdims: bool = ...,
  1257. initial: _NumberLike = ...,
  1258. where: _ArrayLikeBool = ...,
  1259. ) -> Any: ...
  1260. @overload
  1261. def prod(
  1262. self,
  1263. axis: Optional[_ShapeLike] = ...,
  1264. dtype: DTypeLike = ...,
  1265. out: _NdArraySubClass = ...,
  1266. keepdims: bool = ...,
  1267. initial: _NumberLike = ...,
  1268. where: _ArrayLikeBool = ...,
  1269. ) -> _NdArraySubClass: ...
  1270. @overload
  1271. def ptp(
  1272. self,
  1273. axis: Optional[_ShapeLike] = ...,
  1274. out: None = ...,
  1275. keepdims: bool = ...,
  1276. ) -> Any: ...
  1277. @overload
  1278. def ptp(
  1279. self,
  1280. axis: Optional[_ShapeLike] = ...,
  1281. out: _NdArraySubClass = ...,
  1282. keepdims: bool = ...,
  1283. ) -> _NdArraySubClass: ...
  1284. def repeat(
  1285. self,
  1286. repeats: _ArrayLikeIntOrBool,
  1287. axis: Optional[SupportsIndex] = ...,
  1288. ) -> ndarray: ...
  1289. @overload
  1290. def round(
  1291. self: _ArraySelf,
  1292. decimals: SupportsIndex = ...,
  1293. out: None = ...,
  1294. ) -> _ArraySelf: ...
  1295. @overload
  1296. def round(
  1297. self,
  1298. decimals: SupportsIndex = ...,
  1299. out: _NdArraySubClass = ...,
  1300. ) -> _NdArraySubClass: ...
  1301. @overload
  1302. def std(
  1303. self,
  1304. axis: Optional[_ShapeLike] = ...,
  1305. dtype: DTypeLike = ...,
  1306. out: None = ...,
  1307. ddof: int = ...,
  1308. keepdims: bool = ...,
  1309. ) -> Any: ...
  1310. @overload
  1311. def std(
  1312. self,
  1313. axis: Optional[_ShapeLike] = ...,
  1314. dtype: DTypeLike = ...,
  1315. out: _NdArraySubClass = ...,
  1316. ddof: int = ...,
  1317. keepdims: bool = ...,
  1318. ) -> _NdArraySubClass: ...
  1319. @overload
  1320. def sum(
  1321. self,
  1322. axis: Optional[_ShapeLike] = ...,
  1323. dtype: DTypeLike = ...,
  1324. out: None = ...,
  1325. keepdims: bool = ...,
  1326. initial: _NumberLike = ...,
  1327. where: _ArrayLikeBool = ...,
  1328. ) -> Any: ...
  1329. @overload
  1330. def sum(
  1331. self,
  1332. axis: Optional[_ShapeLike] = ...,
  1333. dtype: DTypeLike = ...,
  1334. out: _NdArraySubClass = ...,
  1335. keepdims: bool = ...,
  1336. initial: _NumberLike = ...,
  1337. where: _ArrayLikeBool = ...,
  1338. ) -> _NdArraySubClass: ...
  1339. @overload
  1340. def take(
  1341. self,
  1342. indices: Union[_IntLike, _BoolLike],
  1343. axis: Optional[SupportsIndex] = ...,
  1344. out: None = ...,
  1345. mode: _ModeKind = ...,
  1346. ) -> Any: ...
  1347. @overload
  1348. def take(
  1349. self,
  1350. indices: _ArrayLikeIntOrBool,
  1351. axis: Optional[SupportsIndex] = ...,
  1352. out: None = ...,
  1353. mode: _ModeKind = ...,
  1354. ) -> ndarray: ...
  1355. @overload
  1356. def take(
  1357. self,
  1358. indices: _ArrayLikeIntOrBool,
  1359. axis: Optional[SupportsIndex] = ...,
  1360. out: _NdArraySubClass = ...,
  1361. mode: _ModeKind = ...,
  1362. ) -> _NdArraySubClass: ...
  1363. @overload
  1364. def var(
  1365. self,
  1366. axis: Optional[_ShapeLike] = ...,
  1367. dtype: DTypeLike = ...,
  1368. out: None = ...,
  1369. ddof: int = ...,
  1370. keepdims: bool = ...,
  1371. ) -> Any: ...
  1372. @overload
  1373. def var(
  1374. self,
  1375. axis: Optional[_ShapeLike] = ...,
  1376. dtype: DTypeLike = ...,
  1377. out: _NdArraySubClass = ...,
  1378. ddof: int = ...,
  1379. keepdims: bool = ...,
  1380. ) -> _NdArraySubClass: ...
  1381. _BufferType = Union[ndarray, bytes, bytearray, memoryview]
  1382. _Casting = Literal["no", "equiv", "safe", "same_kind", "unsafe"]
  1383. class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
  1384. @property
  1385. def base(self) -> Optional[ndarray]: ...
  1386. @property
  1387. def ndim(self) -> int: ...
  1388. @property
  1389. def size(self) -> int: ...
  1390. @property
  1391. def real(self: _ArraySelf) -> _ArraySelf: ...
  1392. @real.setter
  1393. def real(self, value: ArrayLike) -> None: ...
  1394. @property
  1395. def imag(self: _ArraySelf) -> _ArraySelf: ...
  1396. @imag.setter
  1397. def imag(self, value: ArrayLike) -> None: ...
  1398. def __new__(
  1399. cls: Type[_ArraySelf],
  1400. shape: _ShapeLike,
  1401. dtype: DTypeLike = ...,
  1402. buffer: _BufferType = ...,
  1403. offset: int = ...,
  1404. strides: _ShapeLike = ...,
  1405. order: _OrderKACF = ...,
  1406. ) -> _ArraySelf: ...
  1407. @property
  1408. def dtype(self) -> _DType: ...
  1409. @property
  1410. def ctypes(self) -> _ctypes: ...
  1411. @property
  1412. def shape(self) -> _Shape: ...
  1413. @shape.setter
  1414. def shape(self, value: _ShapeLike): ...
  1415. @property
  1416. def strides(self) -> _Shape: ...
  1417. @strides.setter
  1418. def strides(self, value: _ShapeLike): ...
  1419. def byteswap(self: _ArraySelf, inplace: bool = ...) -> _ArraySelf: ...
  1420. def fill(self, value: Any) -> None: ...
  1421. @property
  1422. def flat(self: _ArraySelf) -> flatiter[_ArraySelf]: ...
  1423. @overload
  1424. def item(self, *args: SupportsIndex) -> Any: ...
  1425. @overload
  1426. def item(self, __args: Tuple[SupportsIndex, ...]) -> Any: ...
  1427. @overload
  1428. def itemset(self, __value: Any) -> None: ...
  1429. @overload
  1430. def itemset(self, __item: _ShapeLike, __value: Any) -> None: ...
  1431. @overload
  1432. def resize(self, __new_shape: _ShapeLike, *, refcheck: bool = ...) -> None: ...
  1433. @overload
  1434. def resize(self, *new_shape: SupportsIndex, refcheck: bool = ...) -> None: ...
  1435. def setflags(
  1436. self, write: bool = ..., align: bool = ..., uic: bool = ...
  1437. ) -> None: ...
  1438. def squeeze(
  1439. self: _ArraySelf, axis: Union[SupportsIndex, Tuple[SupportsIndex, ...]] = ...
  1440. ) -> _ArraySelf: ...
  1441. def swapaxes(self: _ArraySelf, axis1: SupportsIndex, axis2: SupportsIndex) -> _ArraySelf: ...
  1442. @overload
  1443. def transpose(self: _ArraySelf, __axes: _ShapeLike) -> _ArraySelf: ...
  1444. @overload
  1445. def transpose(self: _ArraySelf, *axes: SupportsIndex) -> _ArraySelf: ...
  1446. def argpartition(
  1447. self,
  1448. kth: _ArrayLikeIntOrBool,
  1449. axis: Optional[SupportsIndex] = ...,
  1450. kind: _PartitionKind = ...,
  1451. order: Union[None, str, Sequence[str]] = ...,
  1452. ) -> ndarray: ...
  1453. def diagonal(
  1454. self: _ArraySelf,
  1455. offset: SupportsIndex = ...,
  1456. axis1: SupportsIndex = ...,
  1457. axis2: SupportsIndex = ...,
  1458. ) -> _ArraySelf: ...
  1459. @overload
  1460. def dot(self, b: ArrayLike, out: None = ...) -> Any: ...
  1461. @overload
  1462. def dot(self, b: ArrayLike, out: _NdArraySubClass = ...) -> _NdArraySubClass: ...
  1463. # `nonzero()` is deprecated for 0d arrays/generics
  1464. def nonzero(self) -> Tuple[ndarray, ...]: ...
  1465. def partition(
  1466. self,
  1467. kth: _ArrayLikeIntOrBool,
  1468. axis: SupportsIndex = ...,
  1469. kind: _PartitionKind = ...,
  1470. order: Union[None, str, Sequence[str]] = ...,
  1471. ) -> None: ...
  1472. # `put` is technically available to `generic`,
  1473. # but is pointless as `generic`s are immutable
  1474. def put(
  1475. self, ind: _ArrayLikeIntOrBool, v: ArrayLike, mode: _ModeKind = ...
  1476. ) -> None: ...
  1477. def searchsorted(
  1478. self, # >= 1D array
  1479. v: ArrayLike,
  1480. side: _SortSide = ...,
  1481. sorter: Optional[_ArrayLikeIntOrBool] = ..., # 1D int array
  1482. ) -> ndarray: ...
  1483. def setfield(
  1484. self, val: ArrayLike, dtype: DTypeLike, offset: SupportsIndex = ...
  1485. ) -> None: ...
  1486. def sort(
  1487. self,
  1488. axis: SupportsIndex = ...,
  1489. kind: Optional[_SortKind] = ...,
  1490. order: Union[None, str, Sequence[str]] = ...,
  1491. ) -> None: ...
  1492. @overload
  1493. def trace(
  1494. self, # >= 2D array
  1495. offset: SupportsIndex = ...,
  1496. axis1: SupportsIndex = ...,
  1497. axis2: SupportsIndex = ...,
  1498. dtype: DTypeLike = ...,
  1499. out: None = ...,
  1500. ) -> Any: ...
  1501. @overload
  1502. def trace(
  1503. self, # >= 2D array
  1504. offset: SupportsIndex = ...,
  1505. axis1: SupportsIndex = ...,
  1506. axis2: SupportsIndex = ...,
  1507. dtype: DTypeLike = ...,
  1508. out: _NdArraySubClass = ...,
  1509. ) -> _NdArraySubClass: ...
  1510. # Many of these special methods are irrelevant currently, since protocols
  1511. # aren't supported yet. That said, I'm adding them for completeness.
  1512. # https://docs.python.org/3/reference/datamodel.html
  1513. def __int__(self) -> int: ...
  1514. def __float__(self) -> float: ...
  1515. def __complex__(self) -> complex: ...
  1516. def __len__(self) -> int: ...
  1517. def __setitem__(self, key, value): ...
  1518. def __iter__(self) -> Any: ...
  1519. def __contains__(self, key) -> bool: ...
  1520. def __index__(self) -> int: ...
  1521. def __matmul__(self, other: ArrayLike) -> Any: ...
  1522. # NOTE: `ndarray` does not implement `__imatmul__`
  1523. def __rmatmul__(self, other: ArrayLike) -> Any: ...
  1524. def __neg__(self: _ArraySelf) -> Any: ...
  1525. def __pos__(self: _ArraySelf) -> Any: ...
  1526. def __abs__(self: _ArraySelf) -> Any: ...
  1527. def __mod__(self, other: ArrayLike) -> Any: ...
  1528. def __rmod__(self, other: ArrayLike) -> Any: ...
  1529. def __divmod__(self, other: ArrayLike) -> Tuple[Any, Any]: ...
  1530. def __rdivmod__(self, other: ArrayLike) -> Tuple[Any, Any]: ...
  1531. def __add__(self, other: ArrayLike) -> Any: ...
  1532. def __radd__(self, other: ArrayLike) -> Any: ...
  1533. def __sub__(self, other: ArrayLike) -> Any: ...
  1534. def __rsub__(self, other: ArrayLike) -> Any: ...
  1535. def __mul__(self, other: ArrayLike) -> Any: ...
  1536. def __rmul__(self, other: ArrayLike) -> Any: ...
  1537. def __floordiv__(self, other: ArrayLike) -> Any: ...
  1538. def __rfloordiv__(self, other: ArrayLike) -> Any: ...
  1539. def __pow__(self, other: ArrayLike) -> Any: ...
  1540. def __rpow__(self, other: ArrayLike) -> Any: ...
  1541. def __truediv__(self, other: ArrayLike) -> Any: ...
  1542. def __rtruediv__(self, other: ArrayLike) -> Any: ...
  1543. def __invert__(self: _ArraySelf) -> Any: ...
  1544. def __lshift__(self, other: ArrayLike) -> Any: ...
  1545. def __rlshift__(self, other: ArrayLike) -> Any: ...
  1546. def __rshift__(self, other: ArrayLike) -> Any: ...
  1547. def __rrshift__(self, other: ArrayLike) -> Any: ...
  1548. def __and__(self, other: ArrayLike) -> Any: ...
  1549. def __rand__(self, other: ArrayLike) -> Any: ...
  1550. def __xor__(self, other: ArrayLike) -> Any: ...
  1551. def __rxor__(self, other: ArrayLike) -> Any: ...
  1552. def __or__(self, other: ArrayLike) -> Any: ...
  1553. def __ror__(self, other: ArrayLike) -> Any: ...
  1554. # `np.generic` does not support inplace operations
  1555. def __iadd__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1556. def __isub__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1557. def __imul__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1558. def __itruediv__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1559. def __ifloordiv__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1560. def __ipow__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1561. def __imod__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1562. def __ilshift__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1563. def __irshift__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1564. def __iand__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1565. def __ixor__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1566. def __ior__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
  1567. # NOTE: while `np.generic` is not technically an instance of `ABCMeta`,
  1568. # the `@abstractmethod` decorator is herein used to (forcefully) deny
  1569. # the creation of `np.generic` instances.
  1570. # The `# type: ignore` comments are necessary to silence mypy errors regarding
  1571. # the missing `ABCMeta` metaclass.
  1572. # See https://github.com/numpy/numpy-stubs/pull/80 for more details.
  1573. _ScalarType = TypeVar("_ScalarType", bound=generic)
  1574. _NBit_co = TypeVar("_NBit_co", covariant=True, bound=NBitBase)
  1575. _NBit_co2 = TypeVar("_NBit_co2", covariant=True, bound=NBitBase)
  1576. class generic(_ArrayOrScalarCommon):
  1577. @abstractmethod
  1578. def __init__(self, *args: Any, **kwargs: Any) -> None: ...
  1579. @property
  1580. def base(self) -> None: ...
  1581. @property
  1582. def dtype(self: _ScalarType) -> _DType[_ScalarType]: ...
  1583. @property
  1584. def ndim(self) -> Literal[0]: ...
  1585. @property
  1586. def size(self) -> Literal[1]: ...
  1587. @property
  1588. def shape(self) -> Tuple[()]: ...
  1589. @property
  1590. def strides(self) -> Tuple[()]: ...
  1591. def byteswap(self: _ScalarType, inplace: Literal[False] = ...) -> _ScalarType: ...
  1592. @property
  1593. def flat(self) -> flatiter[ndarray]: ...
  1594. def item(
  1595. self: _ScalarType,
  1596. __args: Union[Literal[0], Tuple[()], Tuple[Literal[0]]] = ...,
  1597. ) -> Any: ...
  1598. def squeeze(
  1599. self: _ScalarType, axis: Union[Literal[0], Tuple[()]] = ...
  1600. ) -> _ScalarType: ...
  1601. def transpose(self: _ScalarType, __axes: Tuple[()] = ...) -> _ScalarType: ...
  1602. class number(generic, Generic[_NBit_co]): # type: ignore
  1603. @property
  1604. def real(self: _ArraySelf) -> _ArraySelf: ...
  1605. @property
  1606. def imag(self: _ArraySelf) -> _ArraySelf: ...
  1607. def __int__(self) -> int: ...
  1608. def __float__(self) -> float: ...
  1609. def __complex__(self) -> complex: ...
  1610. def __neg__(self: _ArraySelf) -> _ArraySelf: ...
  1611. def __pos__(self: _ArraySelf) -> _ArraySelf: ...
  1612. def __abs__(self: _ArraySelf) -> _ArraySelf: ...
  1613. # Ensure that objects annotated as `number` support arithmetic operations
  1614. __add__: _NumberOp
  1615. __radd__: _NumberOp
  1616. __sub__: _NumberOp
  1617. __rsub__: _NumberOp
  1618. __mul__: _NumberOp
  1619. __rmul__: _NumberOp
  1620. __floordiv__: _NumberOp
  1621. __rfloordiv__: _NumberOp
  1622. __pow__: _NumberOp
  1623. __rpow__: _NumberOp
  1624. __truediv__: _NumberOp
  1625. __rtruediv__: _NumberOp
  1626. class bool_(generic):
  1627. def __init__(self, __value: object = ...) -> None: ...
  1628. @property
  1629. def real(self: _ArraySelf) -> _ArraySelf: ...
  1630. @property
  1631. def imag(self: _ArraySelf) -> _ArraySelf: ...
  1632. def __int__(self) -> int: ...
  1633. def __float__(self) -> float: ...
  1634. def __complex__(self) -> complex: ...
  1635. def __abs__(self: _ArraySelf) -> _ArraySelf: ...
  1636. __add__: _BoolOp[bool_]
  1637. __radd__: _BoolOp[bool_]
  1638. __sub__: _BoolSub
  1639. __rsub__: _BoolSub
  1640. __mul__: _BoolOp[bool_]
  1641. __rmul__: _BoolOp[bool_]
  1642. __floordiv__: _BoolOp[int8]
  1643. __rfloordiv__: _BoolOp[int8]
  1644. __pow__: _BoolOp[int8]
  1645. __rpow__: _BoolOp[int8]
  1646. __truediv__: _BoolTrueDiv
  1647. __rtruediv__: _BoolTrueDiv
  1648. def __invert__(self) -> bool_: ...
  1649. __lshift__: _BoolBitOp[int8]
  1650. __rlshift__: _BoolBitOp[int8]
  1651. __rshift__: _BoolBitOp[int8]
  1652. __rrshift__: _BoolBitOp[int8]
  1653. __and__: _BoolBitOp[bool_]
  1654. __rand__: _BoolBitOp[bool_]
  1655. __xor__: _BoolBitOp[bool_]
  1656. __rxor__: _BoolBitOp[bool_]
  1657. __or__: _BoolBitOp[bool_]
  1658. __ror__: _BoolBitOp[bool_]
  1659. __mod__: _BoolMod
  1660. __rmod__: _BoolMod
  1661. __divmod__: _BoolDivMod
  1662. __rdivmod__: _BoolDivMod
  1663. class object_(generic):
  1664. def __init__(self, __value: object = ...) -> None: ...
  1665. @property
  1666. def real(self: _ArraySelf) -> _ArraySelf: ...
  1667. @property
  1668. def imag(self: _ArraySelf) -> _ArraySelf: ...
  1669. # The `datetime64` constructors requires an object with the three attributes below,
  1670. # and thus supports datetime duck typing
  1671. class _DatetimeScalar(Protocol):
  1672. @property
  1673. def day(self) -> int: ...
  1674. @property
  1675. def month(self) -> int: ...
  1676. @property
  1677. def year(self) -> int: ...
  1678. class datetime64(generic):
  1679. @overload
  1680. def __init__(
  1681. self,
  1682. __value: Union[None, datetime64, _CharLike, _DatetimeScalar] = ...,
  1683. __format: Union[_CharLike, Tuple[_CharLike, _IntLike]] = ...,
  1684. ) -> None: ...
  1685. @overload
  1686. def __init__(
  1687. self,
  1688. __value: int,
  1689. __format: Union[_CharLike, Tuple[_CharLike, _IntLike]]
  1690. ) -> None: ...
  1691. def __add__(self, other: Union[timedelta64, _IntLike, _BoolLike]) -> datetime64: ...
  1692. def __radd__(self, other: Union[timedelta64, _IntLike, _BoolLike]) -> datetime64: ...
  1693. @overload
  1694. def __sub__(self, other: datetime64) -> timedelta64: ...
  1695. @overload
  1696. def __sub__(self, other: Union[timedelta64, _IntLike, _BoolLike]) -> datetime64: ...
  1697. def __rsub__(self, other: datetime64) -> timedelta64: ...
  1698. # Support for `__index__` was added in python 3.8 (bpo-20092)
  1699. if sys.version_info >= (3, 8):
  1700. _IntValue = Union[SupportsInt, _CharLike, SupportsIndex]
  1701. _FloatValue = Union[None, _CharLike, SupportsFloat, SupportsIndex]
  1702. _ComplexValue = Union[None, _CharLike, SupportsFloat, SupportsComplex, SupportsIndex]
  1703. else:
  1704. _IntValue = Union[SupportsInt, _CharLike]
  1705. _FloatValue = Union[None, _CharLike, SupportsFloat]
  1706. _ComplexValue = Union[None, _CharLike, SupportsFloat, SupportsComplex]
  1707. class integer(number[_NBit_co]): # type: ignore
  1708. # NOTE: `__index__` is technically defined in the bottom-most
  1709. # sub-classes (`int64`, `uint32`, etc)
  1710. def __index__(self) -> int: ...
  1711. __truediv__: _IntTrueDiv[_NBit_co]
  1712. __rtruediv__: _IntTrueDiv[_NBit_co]
  1713. def __mod__(self, value: Union[_IntLike, integer]) -> integer: ...
  1714. def __rmod__(self, value: Union[_IntLike, integer]) -> integer: ...
  1715. def __invert__(self: _IntType) -> _IntType: ...
  1716. # Ensure that objects annotated as `integer` support bit-wise operations
  1717. def __lshift__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
  1718. def __rlshift__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
  1719. def __rshift__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
  1720. def __rrshift__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
  1721. def __and__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
  1722. def __rand__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
  1723. def __or__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
  1724. def __ror__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
  1725. def __xor__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
  1726. def __rxor__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
  1727. class signedinteger(integer[_NBit_co]):
  1728. def __init__(self, __value: _IntValue = ...) -> None: ...
  1729. __add__: _SignedIntOp[_NBit_co]
  1730. __radd__: _SignedIntOp[_NBit_co]
  1731. __sub__: _SignedIntOp[_NBit_co]
  1732. __rsub__: _SignedIntOp[_NBit_co]
  1733. __mul__: _SignedIntOp[_NBit_co]
  1734. __rmul__: _SignedIntOp[_NBit_co]
  1735. __floordiv__: _SignedIntOp[_NBit_co]
  1736. __rfloordiv__: _SignedIntOp[_NBit_co]
  1737. __pow__: _SignedIntOp[_NBit_co]
  1738. __rpow__: _SignedIntOp[_NBit_co]
  1739. __lshift__: _SignedIntBitOp[_NBit_co]
  1740. __rlshift__: _SignedIntBitOp[_NBit_co]
  1741. __rshift__: _SignedIntBitOp[_NBit_co]
  1742. __rrshift__: _SignedIntBitOp[_NBit_co]
  1743. __and__: _SignedIntBitOp[_NBit_co]
  1744. __rand__: _SignedIntBitOp[_NBit_co]
  1745. __xor__: _SignedIntBitOp[_NBit_co]
  1746. __rxor__: _SignedIntBitOp[_NBit_co]
  1747. __or__: _SignedIntBitOp[_NBit_co]
  1748. __ror__: _SignedIntBitOp[_NBit_co]
  1749. __mod__: _SignedIntMod[_NBit_co]
  1750. __rmod__: _SignedIntMod[_NBit_co]
  1751. __divmod__: _SignedIntDivMod[_NBit_co]
  1752. __rdivmod__: _SignedIntDivMod[_NBit_co]
  1753. int8 = signedinteger[_8Bit]
  1754. int16 = signedinteger[_16Bit]
  1755. int32 = signedinteger[_32Bit]
  1756. int64 = signedinteger[_64Bit]
  1757. class timedelta64(generic):
  1758. def __init__(
  1759. self,
  1760. __value: Union[None, int, _CharLike, dt.timedelta, timedelta64] = ...,
  1761. __format: Union[_CharLike, Tuple[_CharLike, _IntLike]] = ...,
  1762. ) -> None: ...
  1763. def __int__(self) -> int: ...
  1764. def __float__(self) -> float: ...
  1765. def __complex__(self) -> complex: ...
  1766. def __neg__(self: _ArraySelf) -> _ArraySelf: ...
  1767. def __pos__(self: _ArraySelf) -> _ArraySelf: ...
  1768. def __abs__(self: _ArraySelf) -> _ArraySelf: ...
  1769. def __add__(self, other: Union[timedelta64, _IntLike, _BoolLike]) -> timedelta64: ...
  1770. def __radd__(self, other: Union[timedelta64, _IntLike, _BoolLike]) -> timedelta64: ...
  1771. def __sub__(self, other: Union[timedelta64, _IntLike, _BoolLike]) -> timedelta64: ...
  1772. def __rsub__(self, other: Union[timedelta64, _IntLike, _BoolLike]) -> timedelta64: ...
  1773. def __mul__(self, other: Union[_FloatLike, _BoolLike]) -> timedelta64: ...
  1774. def __rmul__(self, other: Union[_FloatLike, _BoolLike]) -> timedelta64: ...
  1775. __truediv__: _TD64Div[float64]
  1776. __floordiv__: _TD64Div[int64]
  1777. def __rtruediv__(self, other: timedelta64) -> float64: ...
  1778. def __rfloordiv__(self, other: timedelta64) -> int64: ...
  1779. def __mod__(self, other: timedelta64) -> timedelta64: ...
  1780. def __rmod__(self, other: timedelta64) -> timedelta64: ...
  1781. def __divmod__(self, other: timedelta64) -> Tuple[int64, timedelta64]: ...
  1782. def __rdivmod__(self, other: timedelta64) -> Tuple[int64, timedelta64]: ...
  1783. class unsignedinteger(integer[_NBit_co]):
  1784. # NOTE: `uint64 + signedinteger -> float64`
  1785. def __init__(self, __value: _IntValue = ...) -> None: ...
  1786. __add__: _UnsignedIntOp[_NBit_co]
  1787. __radd__: _UnsignedIntOp[_NBit_co]
  1788. __sub__: _UnsignedIntOp[_NBit_co]
  1789. __rsub__: _UnsignedIntOp[_NBit_co]
  1790. __mul__: _UnsignedIntOp[_NBit_co]
  1791. __rmul__: _UnsignedIntOp[_NBit_co]
  1792. __floordiv__: _UnsignedIntOp[_NBit_co]
  1793. __rfloordiv__: _UnsignedIntOp[_NBit_co]
  1794. __pow__: _UnsignedIntOp[_NBit_co]
  1795. __rpow__: _UnsignedIntOp[_NBit_co]
  1796. __lshift__: _UnsignedIntBitOp[_NBit_co]
  1797. __rlshift__: _UnsignedIntBitOp[_NBit_co]
  1798. __rshift__: _UnsignedIntBitOp[_NBit_co]
  1799. __rrshift__: _UnsignedIntBitOp[_NBit_co]
  1800. __and__: _UnsignedIntBitOp[_NBit_co]
  1801. __rand__: _UnsignedIntBitOp[_NBit_co]
  1802. __xor__: _UnsignedIntBitOp[_NBit_co]
  1803. __rxor__: _UnsignedIntBitOp[_NBit_co]
  1804. __or__: _UnsignedIntBitOp[_NBit_co]
  1805. __ror__: _UnsignedIntBitOp[_NBit_co]
  1806. __mod__: _UnsignedIntMod[_NBit_co]
  1807. __rmod__: _UnsignedIntMod[_NBit_co]
  1808. __divmod__: _UnsignedIntDivMod[_NBit_co]
  1809. __rdivmod__: _UnsignedIntDivMod[_NBit_co]
  1810. uint8 = unsignedinteger[_8Bit]
  1811. uint16 = unsignedinteger[_16Bit]
  1812. uint32 = unsignedinteger[_32Bit]
  1813. uint64 = unsignedinteger[_64Bit]
  1814. class inexact(number[_NBit_co]): ... # type: ignore
  1815. _IntType = TypeVar("_IntType", bound=integer)
  1816. _FloatType = TypeVar('_FloatType', bound=floating)
  1817. class floating(inexact[_NBit_co]):
  1818. def __init__(self, __value: _FloatValue = ...) -> None: ...
  1819. __add__: _FloatOp[_NBit_co]
  1820. __radd__: _FloatOp[_NBit_co]
  1821. __sub__: _FloatOp[_NBit_co]
  1822. __rsub__: _FloatOp[_NBit_co]
  1823. __mul__: _FloatOp[_NBit_co]
  1824. __rmul__: _FloatOp[_NBit_co]
  1825. __truediv__: _FloatOp[_NBit_co]
  1826. __rtruediv__: _FloatOp[_NBit_co]
  1827. __floordiv__: _FloatOp[_NBit_co]
  1828. __rfloordiv__: _FloatOp[_NBit_co]
  1829. __pow__: _FloatOp[_NBit_co]
  1830. __rpow__: _FloatOp[_NBit_co]
  1831. __mod__: _FloatMod[_NBit_co]
  1832. __rmod__: _FloatMod[_NBit_co]
  1833. __divmod__: _FloatDivMod[_NBit_co]
  1834. __rdivmod__: _FloatDivMod[_NBit_co]
  1835. float16 = floating[_16Bit]
  1836. float32 = floating[_32Bit]
  1837. float64 = floating[_64Bit]
  1838. # The main reason for `complexfloating` having two typevars is cosmetic.
  1839. # It is used to clarify why `complex128`s precision is `_64Bit`, the latter
  1840. # describing the two 64 bit floats representing its real and imaginary component
  1841. class complexfloating(inexact[_NBit_co], Generic[_NBit_co, _NBit_co2]):
  1842. def __init__(self, __value: _ComplexValue = ...) -> None: ...
  1843. @property
  1844. def real(self) -> floating[_NBit_co]: ... # type: ignore[override]
  1845. @property
  1846. def imag(self) -> floating[_NBit_co2]: ... # type: ignore[override]
  1847. def __abs__(self) -> floating[_NBit_co]: ... # type: ignore[override]
  1848. __add__: _ComplexOp[_NBit_co]
  1849. __radd__: _ComplexOp[_NBit_co]
  1850. __sub__: _ComplexOp[_NBit_co]
  1851. __rsub__: _ComplexOp[_NBit_co]
  1852. __mul__: _ComplexOp[_NBit_co]
  1853. __rmul__: _ComplexOp[_NBit_co]
  1854. __truediv__: _ComplexOp[_NBit_co]
  1855. __rtruediv__: _ComplexOp[_NBit_co]
  1856. __floordiv__: _ComplexOp[_NBit_co]
  1857. __rfloordiv__: _ComplexOp[_NBit_co]
  1858. __pow__: _ComplexOp[_NBit_co]
  1859. __rpow__: _ComplexOp[_NBit_co]
  1860. complex64 = complexfloating[_32Bit, _32Bit]
  1861. complex128 = complexfloating[_64Bit, _64Bit]
  1862. class flexible(generic): ... # type: ignore
  1863. class void(flexible):
  1864. def __init__(self, __value: Union[_IntLike, _BoolLike, bytes]): ...
  1865. @property
  1866. def real(self: _ArraySelf) -> _ArraySelf: ...
  1867. @property
  1868. def imag(self: _ArraySelf) -> _ArraySelf: ...
  1869. def setfield(
  1870. self, val: ArrayLike, dtype: DTypeLike, offset: int = ...
  1871. ) -> None: ...
  1872. class character(flexible): # type: ignore
  1873. def __int__(self) -> int: ...
  1874. def __float__(self) -> float: ...
  1875. # NOTE: Most `np.bytes_` / `np.str_` methods return their
  1876. # builtin `bytes` / `str` counterpart
  1877. class bytes_(character, bytes):
  1878. @overload
  1879. def __init__(self, __value: object = ...) -> None: ...
  1880. @overload
  1881. def __init__(
  1882. self, __value: str, encoding: str = ..., errors: str = ...
  1883. ) -> None: ...
  1884. class str_(character, str):
  1885. @overload
  1886. def __init__(self, __value: object = ...) -> None: ...
  1887. @overload
  1888. def __init__(
  1889. self, __value: bytes, encoding: str = ..., errors: str = ...
  1890. ) -> None: ...
  1891. unicode_ = str0 = str_
  1892. # TODO(alan): Platform dependent types
  1893. # longcomplex, longdouble, longfloat
  1894. # bytes, short, intc, intp, longlong
  1895. # half, single, double, longdouble
  1896. # uint_, int_, float_, complex_
  1897. # float128, complex256
  1898. # float96
  1899. def array(
  1900. object: object,
  1901. dtype: DTypeLike = ...,
  1902. *,
  1903. copy: bool = ...,
  1904. order: _OrderKACF = ...,
  1905. subok: bool = ...,
  1906. ndmin: int = ...,
  1907. like: ArrayLike = ...,
  1908. ) -> ndarray: ...
  1909. def zeros(
  1910. shape: _ShapeLike,
  1911. dtype: DTypeLike = ...,
  1912. order: _OrderCF = ...,
  1913. *,
  1914. like: ArrayLike = ...,
  1915. ) -> ndarray: ...
  1916. def empty(
  1917. shape: _ShapeLike,
  1918. dtype: DTypeLike = ...,
  1919. order: _OrderCF = ...,
  1920. *,
  1921. like: ArrayLike = ...,
  1922. ) -> ndarray: ...
  1923. def broadcast_shapes(*args: _ShapeLike) -> _Shape: ...
  1924. #
  1925. # Constants
  1926. #
  1927. Inf: Final[float]
  1928. Infinity: Final[float]
  1929. NAN: Final[float]
  1930. NINF: Final[float]
  1931. NZERO: Final[float]
  1932. NaN: Final[float]
  1933. PINF: Final[float]
  1934. PZERO: Final[float]
  1935. e: Final[float]
  1936. euler_gamma: Final[float]
  1937. inf: Final[float]
  1938. infty: Final[float]
  1939. nan: Final[float]
  1940. pi: Final[float]
  1941. ALLOW_THREADS: Final[int]
  1942. BUFSIZE: Final[int]
  1943. CLIP: Final[int]
  1944. ERR_CALL: Final[int]
  1945. ERR_DEFAULT: Final[int]
  1946. ERR_IGNORE: Final[int]
  1947. ERR_LOG: Final[int]
  1948. ERR_PRINT: Final[int]
  1949. ERR_RAISE: Final[int]
  1950. ERR_WARN: Final[int]
  1951. FLOATING_POINT_SUPPORT: Final[int]
  1952. FPE_DIVIDEBYZERO: Final[int]
  1953. FPE_INVALID: Final[int]
  1954. FPE_OVERFLOW: Final[int]
  1955. FPE_UNDERFLOW: Final[int]
  1956. MAXDIMS: Final[int]
  1957. MAY_SHARE_BOUNDS: Final[int]
  1958. MAY_SHARE_EXACT: Final[int]
  1959. RAISE: Final[int]
  1960. SHIFT_DIVIDEBYZERO: Final[int]
  1961. SHIFT_INVALID: Final[int]
  1962. SHIFT_OVERFLOW: Final[int]
  1963. SHIFT_UNDERFLOW: Final[int]
  1964. UFUNC_BUFSIZE_DEFAULT: Final[int]
  1965. WRAP: Final[int]
  1966. tracemalloc_domain: Final[int]
  1967. little_endian: Final[bool]
  1968. True_: Final[bool_]
  1969. False_: Final[bool_]
  1970. UFUNC_PYVALS_NAME: Final[str]
  1971. class ufunc:
  1972. @property
  1973. def __name__(self) -> str: ...
  1974. def __call__(
  1975. self,
  1976. *args: ArrayLike,
  1977. out: Optional[Union[ndarray, Tuple[ndarray, ...]]] = ...,
  1978. where: Optional[ndarray] = ...,
  1979. # The list should be a list of tuples of ints, but since we
  1980. # don't know the signature it would need to be
  1981. # Tuple[int, ...]. But, since List is invariant something like
  1982. # e.g. List[Tuple[int, int]] isn't a subtype of
  1983. # List[Tuple[int, ...]], so we can't type precisely here.
  1984. axes: List[Any] = ...,
  1985. axis: int = ...,
  1986. keepdims: bool = ...,
  1987. casting: _Casting = ...,
  1988. order: _OrderKACF = ...,
  1989. dtype: DTypeLike = ...,
  1990. subok: bool = ...,
  1991. signature: Union[str, Tuple[str]] = ...,
  1992. # In reality this should be a length of list 3 containing an
  1993. # int, an int, and a callable, but there's no way to express
  1994. # that.
  1995. extobj: List[Union[int, Callable]] = ...,
  1996. ) -> Any: ...
  1997. @property
  1998. def nin(self) -> int: ...
  1999. @property
  2000. def nout(self) -> int: ...
  2001. @property
  2002. def nargs(self) -> int: ...
  2003. @property
  2004. def ntypes(self) -> int: ...
  2005. @property
  2006. def types(self) -> List[str]: ...
  2007. # Broad return type because it has to encompass things like
  2008. #
  2009. # >>> np.logical_and.identity is True
  2010. # True
  2011. # >>> np.add.identity is 0
  2012. # True
  2013. # >>> np.sin.identity is None
  2014. # True
  2015. #
  2016. # and any user-defined ufuncs.
  2017. @property
  2018. def identity(self) -> Any: ...
  2019. # This is None for ufuncs and a string for gufuncs.
  2020. @property
  2021. def signature(self) -> Optional[str]: ...
  2022. # The next four methods will always exist, but they will just
  2023. # raise a ValueError ufuncs with that don't accept two input
  2024. # arguments and return one output argument. Because of that we
  2025. # can't type them very precisely.
  2026. @property
  2027. def reduce(self) -> Any: ...
  2028. @property
  2029. def accumulate(self) -> Any: ...
  2030. @property
  2031. def reduceat(self) -> Any: ...
  2032. @property
  2033. def outer(self) -> Any: ...
  2034. # Similarly at won't be defined for ufuncs that return multiple
  2035. # outputs, so we can't type it very precisely.
  2036. @property
  2037. def at(self) -> Any: ...
  2038. absolute: ufunc
  2039. add: ufunc
  2040. arccos: ufunc
  2041. arccosh: ufunc
  2042. arcsin: ufunc
  2043. arcsinh: ufunc
  2044. arctan2: ufunc
  2045. arctan: ufunc
  2046. arctanh: ufunc
  2047. bitwise_and: ufunc
  2048. bitwise_or: ufunc
  2049. bitwise_xor: ufunc
  2050. cbrt: ufunc
  2051. ceil: ufunc
  2052. conjugate: ufunc
  2053. copysign: ufunc
  2054. cos: ufunc
  2055. cosh: ufunc
  2056. deg2rad: ufunc
  2057. degrees: ufunc
  2058. divmod: ufunc
  2059. equal: ufunc
  2060. exp2: ufunc
  2061. exp: ufunc
  2062. expm1: ufunc
  2063. fabs: ufunc
  2064. float_power: ufunc
  2065. floor: ufunc
  2066. floor_divide: ufunc
  2067. fmax: ufunc
  2068. fmin: ufunc
  2069. fmod: ufunc
  2070. frexp: ufunc
  2071. gcd: ufunc
  2072. greater: ufunc
  2073. greater_equal: ufunc
  2074. heaviside: ufunc
  2075. hypot: ufunc
  2076. invert: ufunc
  2077. isfinite: ufunc
  2078. isinf: ufunc
  2079. isnan: ufunc
  2080. isnat: ufunc
  2081. lcm: ufunc
  2082. ldexp: ufunc
  2083. left_shift: ufunc
  2084. less: ufunc
  2085. less_equal: ufunc
  2086. log10: ufunc
  2087. log1p: ufunc
  2088. log2: ufunc
  2089. log: ufunc
  2090. logaddexp2: ufunc
  2091. logaddexp: ufunc
  2092. logical_and: ufunc
  2093. logical_not: ufunc
  2094. logical_or: ufunc
  2095. logical_xor: ufunc
  2096. matmul: ufunc
  2097. maximum: ufunc
  2098. minimum: ufunc
  2099. modf: ufunc
  2100. multiply: ufunc
  2101. negative: ufunc
  2102. nextafter: ufunc
  2103. not_equal: ufunc
  2104. positive: ufunc
  2105. power: ufunc
  2106. rad2deg: ufunc
  2107. radians: ufunc
  2108. reciprocal: ufunc
  2109. remainder: ufunc
  2110. right_shift: ufunc
  2111. rint: ufunc
  2112. sign: ufunc
  2113. signbit: ufunc
  2114. sin: ufunc
  2115. sinh: ufunc
  2116. spacing: ufunc
  2117. sqrt: ufunc
  2118. square: ufunc
  2119. subtract: ufunc
  2120. tan: ufunc
  2121. tanh: ufunc
  2122. true_divide: ufunc
  2123. trunc: ufunc
  2124. abs = absolute
  2125. # Warnings
  2126. class ModuleDeprecationWarning(DeprecationWarning): ...
  2127. class VisibleDeprecationWarning(UserWarning): ...
  2128. class ComplexWarning(RuntimeWarning): ...
  2129. class RankWarning(UserWarning): ...
  2130. # Errors
  2131. class TooHardError(RuntimeError): ...
  2132. class AxisError(ValueError, IndexError):
  2133. def __init__(
  2134. self, axis: int, ndim: Optional[int] = ..., msg_prefix: Optional[str] = ...
  2135. ) -> None: ...
  2136. _CallType = TypeVar("_CallType", bound=Union[_ErrFunc, _SupportsWrite])
  2137. class errstate(Generic[_CallType], ContextDecorator):
  2138. call: _CallType
  2139. kwargs: _ErrDictOptional
  2140. # Expand `**kwargs` into explicit keyword-only arguments
  2141. def __init__(
  2142. self,
  2143. *,
  2144. call: _CallType = ...,
  2145. all: Optional[_ErrKind] = ...,
  2146. divide: Optional[_ErrKind] = ...,
  2147. over: Optional[_ErrKind] = ...,
  2148. under: Optional[_ErrKind] = ...,
  2149. invalid: Optional[_ErrKind] = ...,
  2150. ) -> None: ...
  2151. def __enter__(self) -> None: ...
  2152. def __exit__(
  2153. self,
  2154. __exc_type: Optional[Type[BaseException]],
  2155. __exc_value: Optional[BaseException],
  2156. __traceback: Optional[TracebackType],
  2157. ) -> None: ...