numpy 2.3.5__cp313-cp313-macosx_14_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of numpy might be problematic. Click here for more details.

Files changed (897) hide show
  1. numpy/__config__.py +170 -0
  2. numpy/__config__.pyi +102 -0
  3. numpy/__init__.cython-30.pxd +1241 -0
  4. numpy/__init__.pxd +1154 -0
  5. numpy/__init__.py +945 -0
  6. numpy/__init__.pyi +6147 -0
  7. numpy/_array_api_info.py +346 -0
  8. numpy/_array_api_info.pyi +207 -0
  9. numpy/_configtool.py +39 -0
  10. numpy/_configtool.pyi +1 -0
  11. numpy/_core/__init__.py +186 -0
  12. numpy/_core/__init__.pyi +2 -0
  13. numpy/_core/_add_newdocs.py +6967 -0
  14. numpy/_core/_add_newdocs.pyi +3 -0
  15. numpy/_core/_add_newdocs_scalars.py +390 -0
  16. numpy/_core/_add_newdocs_scalars.pyi +16 -0
  17. numpy/_core/_asarray.py +134 -0
  18. numpy/_core/_asarray.pyi +41 -0
  19. numpy/_core/_dtype.py +366 -0
  20. numpy/_core/_dtype.pyi +58 -0
  21. numpy/_core/_dtype_ctypes.py +120 -0
  22. numpy/_core/_dtype_ctypes.pyi +83 -0
  23. numpy/_core/_exceptions.py +162 -0
  24. numpy/_core/_exceptions.pyi +55 -0
  25. numpy/_core/_internal.py +958 -0
  26. numpy/_core/_internal.pyi +72 -0
  27. numpy/_core/_machar.py +355 -0
  28. numpy/_core/_machar.pyi +55 -0
  29. numpy/_core/_methods.py +255 -0
  30. numpy/_core/_methods.pyi +22 -0
  31. numpy/_core/_multiarray_tests.cpython-313-darwin.so +0 -0
  32. numpy/_core/_multiarray_umath.cpython-313-darwin.so +0 -0
  33. numpy/_core/_operand_flag_tests.cpython-313-darwin.so +0 -0
  34. numpy/_core/_rational_tests.cpython-313-darwin.so +0 -0
  35. numpy/_core/_simd.cpython-313-darwin.so +0 -0
  36. numpy/_core/_simd.pyi +25 -0
  37. numpy/_core/_string_helpers.py +100 -0
  38. numpy/_core/_string_helpers.pyi +12 -0
  39. numpy/_core/_struct_ufunc_tests.cpython-313-darwin.so +0 -0
  40. numpy/_core/_type_aliases.py +119 -0
  41. numpy/_core/_type_aliases.pyi +97 -0
  42. numpy/_core/_ufunc_config.py +491 -0
  43. numpy/_core/_ufunc_config.pyi +78 -0
  44. numpy/_core/_umath_tests.cpython-313-darwin.so +0 -0
  45. numpy/_core/arrayprint.py +1775 -0
  46. numpy/_core/arrayprint.pyi +238 -0
  47. numpy/_core/cversions.py +13 -0
  48. numpy/_core/defchararray.py +1427 -0
  49. numpy/_core/defchararray.pyi +1135 -0
  50. numpy/_core/einsumfunc.py +1498 -0
  51. numpy/_core/einsumfunc.pyi +184 -0
  52. numpy/_core/fromnumeric.py +4269 -0
  53. numpy/_core/fromnumeric.pyi +1750 -0
  54. numpy/_core/function_base.py +545 -0
  55. numpy/_core/function_base.pyi +278 -0
  56. numpy/_core/getlimits.py +748 -0
  57. numpy/_core/getlimits.pyi +3 -0
  58. numpy/_core/include/numpy/__multiarray_api.c +376 -0
  59. numpy/_core/include/numpy/__multiarray_api.h +1628 -0
  60. numpy/_core/include/numpy/__ufunc_api.c +54 -0
  61. numpy/_core/include/numpy/__ufunc_api.h +341 -0
  62. numpy/_core/include/numpy/_neighborhood_iterator_imp.h +90 -0
  63. numpy/_core/include/numpy/_numpyconfig.h +33 -0
  64. numpy/_core/include/numpy/_public_dtype_api_table.h +86 -0
  65. numpy/_core/include/numpy/arrayobject.h +7 -0
  66. numpy/_core/include/numpy/arrayscalars.h +196 -0
  67. numpy/_core/include/numpy/dtype_api.h +480 -0
  68. numpy/_core/include/numpy/halffloat.h +70 -0
  69. numpy/_core/include/numpy/ndarrayobject.h +304 -0
  70. numpy/_core/include/numpy/ndarraytypes.h +1950 -0
  71. numpy/_core/include/numpy/npy_2_compat.h +249 -0
  72. numpy/_core/include/numpy/npy_2_complexcompat.h +28 -0
  73. numpy/_core/include/numpy/npy_3kcompat.h +374 -0
  74. numpy/_core/include/numpy/npy_common.h +977 -0
  75. numpy/_core/include/numpy/npy_cpu.h +124 -0
  76. numpy/_core/include/numpy/npy_endian.h +78 -0
  77. numpy/_core/include/numpy/npy_math.h +602 -0
  78. numpy/_core/include/numpy/npy_no_deprecated_api.h +20 -0
  79. numpy/_core/include/numpy/npy_os.h +42 -0
  80. numpy/_core/include/numpy/numpyconfig.h +182 -0
  81. numpy/_core/include/numpy/random/LICENSE.txt +21 -0
  82. numpy/_core/include/numpy/random/bitgen.h +20 -0
  83. numpy/_core/include/numpy/random/distributions.h +209 -0
  84. numpy/_core/include/numpy/random/libdivide.h +2079 -0
  85. numpy/_core/include/numpy/ufuncobject.h +343 -0
  86. numpy/_core/include/numpy/utils.h +37 -0
  87. numpy/_core/lib/libnpymath.a +0 -0
  88. numpy/_core/lib/npy-pkg-config/mlib.ini +12 -0
  89. numpy/_core/lib/npy-pkg-config/npymath.ini +20 -0
  90. numpy/_core/lib/pkgconfig/numpy.pc +7 -0
  91. numpy/_core/memmap.py +363 -0
  92. numpy/_core/memmap.pyi +3 -0
  93. numpy/_core/multiarray.py +1762 -0
  94. numpy/_core/multiarray.pyi +1285 -0
  95. numpy/_core/numeric.py +2760 -0
  96. numpy/_core/numeric.pyi +882 -0
  97. numpy/_core/numerictypes.py +633 -0
  98. numpy/_core/numerictypes.pyi +197 -0
  99. numpy/_core/overrides.py +183 -0
  100. numpy/_core/overrides.pyi +48 -0
  101. numpy/_core/printoptions.py +32 -0
  102. numpy/_core/printoptions.pyi +28 -0
  103. numpy/_core/records.py +1089 -0
  104. numpy/_core/records.pyi +333 -0
  105. numpy/_core/shape_base.py +998 -0
  106. numpy/_core/shape_base.pyi +175 -0
  107. numpy/_core/strings.py +1829 -0
  108. numpy/_core/strings.pyi +511 -0
  109. numpy/_core/tests/_locales.py +72 -0
  110. numpy/_core/tests/_natype.py +205 -0
  111. numpy/_core/tests/data/astype_copy.pkl +0 -0
  112. numpy/_core/tests/data/generate_umath_validation_data.cpp +170 -0
  113. numpy/_core/tests/data/recarray_from_file.fits +0 -0
  114. numpy/_core/tests/data/umath-validation-set-README.txt +15 -0
  115. numpy/_core/tests/data/umath-validation-set-arccos.csv +1429 -0
  116. numpy/_core/tests/data/umath-validation-set-arccosh.csv +1429 -0
  117. numpy/_core/tests/data/umath-validation-set-arcsin.csv +1429 -0
  118. numpy/_core/tests/data/umath-validation-set-arcsinh.csv +1429 -0
  119. numpy/_core/tests/data/umath-validation-set-arctan.csv +1429 -0
  120. numpy/_core/tests/data/umath-validation-set-arctanh.csv +1429 -0
  121. numpy/_core/tests/data/umath-validation-set-cbrt.csv +1429 -0
  122. numpy/_core/tests/data/umath-validation-set-cos.csv +1375 -0
  123. numpy/_core/tests/data/umath-validation-set-cosh.csv +1429 -0
  124. numpy/_core/tests/data/umath-validation-set-exp.csv +412 -0
  125. numpy/_core/tests/data/umath-validation-set-exp2.csv +1429 -0
  126. numpy/_core/tests/data/umath-validation-set-expm1.csv +1429 -0
  127. numpy/_core/tests/data/umath-validation-set-log.csv +271 -0
  128. numpy/_core/tests/data/umath-validation-set-log10.csv +1629 -0
  129. numpy/_core/tests/data/umath-validation-set-log1p.csv +1429 -0
  130. numpy/_core/tests/data/umath-validation-set-log2.csv +1629 -0
  131. numpy/_core/tests/data/umath-validation-set-sin.csv +1370 -0
  132. numpy/_core/tests/data/umath-validation-set-sinh.csv +1429 -0
  133. numpy/_core/tests/data/umath-validation-set-tan.csv +1429 -0
  134. numpy/_core/tests/data/umath-validation-set-tanh.csv +1429 -0
  135. numpy/_core/tests/examples/cython/checks.pyx +373 -0
  136. numpy/_core/tests/examples/cython/meson.build +43 -0
  137. numpy/_core/tests/examples/cython/setup.py +39 -0
  138. numpy/_core/tests/examples/limited_api/limited_api1.c +17 -0
  139. numpy/_core/tests/examples/limited_api/limited_api2.pyx +11 -0
  140. numpy/_core/tests/examples/limited_api/limited_api_latest.c +19 -0
  141. numpy/_core/tests/examples/limited_api/meson.build +59 -0
  142. numpy/_core/tests/examples/limited_api/setup.py +24 -0
  143. numpy/_core/tests/test__exceptions.py +90 -0
  144. numpy/_core/tests/test_abc.py +54 -0
  145. numpy/_core/tests/test_api.py +654 -0
  146. numpy/_core/tests/test_argparse.py +92 -0
  147. numpy/_core/tests/test_array_api_info.py +113 -0
  148. numpy/_core/tests/test_array_coercion.py +911 -0
  149. numpy/_core/tests/test_array_interface.py +222 -0
  150. numpy/_core/tests/test_arraymethod.py +84 -0
  151. numpy/_core/tests/test_arrayobject.py +75 -0
  152. numpy/_core/tests/test_arrayprint.py +1328 -0
  153. numpy/_core/tests/test_casting_floatingpoint_errors.py +154 -0
  154. numpy/_core/tests/test_casting_unittests.py +817 -0
  155. numpy/_core/tests/test_conversion_utils.py +206 -0
  156. numpy/_core/tests/test_cpu_dispatcher.py +49 -0
  157. numpy/_core/tests/test_cpu_features.py +432 -0
  158. numpy/_core/tests/test_custom_dtypes.py +315 -0
  159. numpy/_core/tests/test_cython.py +351 -0
  160. numpy/_core/tests/test_datetime.py +2734 -0
  161. numpy/_core/tests/test_defchararray.py +825 -0
  162. numpy/_core/tests/test_deprecations.py +454 -0
  163. numpy/_core/tests/test_dlpack.py +190 -0
  164. numpy/_core/tests/test_dtype.py +1995 -0
  165. numpy/_core/tests/test_einsum.py +1317 -0
  166. numpy/_core/tests/test_errstate.py +131 -0
  167. numpy/_core/tests/test_extint128.py +217 -0
  168. numpy/_core/tests/test_function_base.py +503 -0
  169. numpy/_core/tests/test_getlimits.py +205 -0
  170. numpy/_core/tests/test_half.py +568 -0
  171. numpy/_core/tests/test_hashtable.py +35 -0
  172. numpy/_core/tests/test_indexerrors.py +125 -0
  173. numpy/_core/tests/test_indexing.py +1455 -0
  174. numpy/_core/tests/test_item_selection.py +167 -0
  175. numpy/_core/tests/test_limited_api.py +102 -0
  176. numpy/_core/tests/test_longdouble.py +369 -0
  177. numpy/_core/tests/test_machar.py +30 -0
  178. numpy/_core/tests/test_mem_overlap.py +930 -0
  179. numpy/_core/tests/test_mem_policy.py +452 -0
  180. numpy/_core/tests/test_memmap.py +246 -0
  181. numpy/_core/tests/test_multiarray.py +10577 -0
  182. numpy/_core/tests/test_multithreading.py +292 -0
  183. numpy/_core/tests/test_nditer.py +3498 -0
  184. numpy/_core/tests/test_nep50_promotions.py +287 -0
  185. numpy/_core/tests/test_numeric.py +4247 -0
  186. numpy/_core/tests/test_numerictypes.py +651 -0
  187. numpy/_core/tests/test_overrides.py +791 -0
  188. numpy/_core/tests/test_print.py +200 -0
  189. numpy/_core/tests/test_protocols.py +46 -0
  190. numpy/_core/tests/test_records.py +544 -0
  191. numpy/_core/tests/test_regression.py +2670 -0
  192. numpy/_core/tests/test_scalar_ctors.py +207 -0
  193. numpy/_core/tests/test_scalar_methods.py +246 -0
  194. numpy/_core/tests/test_scalarbuffer.py +153 -0
  195. numpy/_core/tests/test_scalarinherit.py +105 -0
  196. numpy/_core/tests/test_scalarmath.py +1176 -0
  197. numpy/_core/tests/test_scalarprint.py +403 -0
  198. numpy/_core/tests/test_shape_base.py +891 -0
  199. numpy/_core/tests/test_simd.py +1341 -0
  200. numpy/_core/tests/test_simd_module.py +103 -0
  201. numpy/_core/tests/test_stringdtype.py +1814 -0
  202. numpy/_core/tests/test_strings.py +1499 -0
  203. numpy/_core/tests/test_ufunc.py +3313 -0
  204. numpy/_core/tests/test_umath.py +4928 -0
  205. numpy/_core/tests/test_umath_accuracy.py +124 -0
  206. numpy/_core/tests/test_umath_complex.py +626 -0
  207. numpy/_core/tests/test_unicode.py +368 -0
  208. numpy/_core/umath.py +60 -0
  209. numpy/_core/umath.pyi +197 -0
  210. numpy/_distributor_init.py +15 -0
  211. numpy/_distributor_init.pyi +1 -0
  212. numpy/_expired_attrs_2_0.py +79 -0
  213. numpy/_expired_attrs_2_0.pyi +62 -0
  214. numpy/_globals.py +96 -0
  215. numpy/_globals.pyi +17 -0
  216. numpy/_pyinstaller/__init__.py +0 -0
  217. numpy/_pyinstaller/__init__.pyi +0 -0
  218. numpy/_pyinstaller/hook-numpy.py +36 -0
  219. numpy/_pyinstaller/hook-numpy.pyi +13 -0
  220. numpy/_pyinstaller/tests/__init__.py +16 -0
  221. numpy/_pyinstaller/tests/pyinstaller-smoke.py +32 -0
  222. numpy/_pyinstaller/tests/test_pyinstaller.py +35 -0
  223. numpy/_pytesttester.py +201 -0
  224. numpy/_pytesttester.pyi +18 -0
  225. numpy/_typing/__init__.py +148 -0
  226. numpy/_typing/_add_docstring.py +153 -0
  227. numpy/_typing/_array_like.py +106 -0
  228. numpy/_typing/_char_codes.py +213 -0
  229. numpy/_typing/_dtype_like.py +114 -0
  230. numpy/_typing/_extended_precision.py +15 -0
  231. numpy/_typing/_nbit.py +19 -0
  232. numpy/_typing/_nbit_base.py +94 -0
  233. numpy/_typing/_nbit_base.pyi +40 -0
  234. numpy/_typing/_nested_sequence.py +79 -0
  235. numpy/_typing/_scalars.py +20 -0
  236. numpy/_typing/_shape.py +8 -0
  237. numpy/_typing/_ufunc.py +7 -0
  238. numpy/_typing/_ufunc.pyi +941 -0
  239. numpy/_utils/__init__.py +95 -0
  240. numpy/_utils/__init__.pyi +30 -0
  241. numpy/_utils/_convertions.py +18 -0
  242. numpy/_utils/_convertions.pyi +4 -0
  243. numpy/_utils/_inspect.py +192 -0
  244. numpy/_utils/_inspect.pyi +71 -0
  245. numpy/_utils/_pep440.py +486 -0
  246. numpy/_utils/_pep440.pyi +121 -0
  247. numpy/char/__init__.py +2 -0
  248. numpy/char/__init__.pyi +111 -0
  249. numpy/conftest.py +258 -0
  250. numpy/core/__init__.py +33 -0
  251. numpy/core/__init__.pyi +0 -0
  252. numpy/core/_dtype.py +10 -0
  253. numpy/core/_dtype.pyi +0 -0
  254. numpy/core/_dtype_ctypes.py +10 -0
  255. numpy/core/_dtype_ctypes.pyi +0 -0
  256. numpy/core/_internal.py +27 -0
  257. numpy/core/_multiarray_umath.py +57 -0
  258. numpy/core/_utils.py +21 -0
  259. numpy/core/arrayprint.py +10 -0
  260. numpy/core/defchararray.py +10 -0
  261. numpy/core/einsumfunc.py +10 -0
  262. numpy/core/fromnumeric.py +10 -0
  263. numpy/core/function_base.py +10 -0
  264. numpy/core/getlimits.py +10 -0
  265. numpy/core/multiarray.py +25 -0
  266. numpy/core/numeric.py +12 -0
  267. numpy/core/numerictypes.py +10 -0
  268. numpy/core/overrides.py +10 -0
  269. numpy/core/overrides.pyi +7 -0
  270. numpy/core/records.py +10 -0
  271. numpy/core/shape_base.py +10 -0
  272. numpy/core/umath.py +10 -0
  273. numpy/ctypeslib/__init__.py +13 -0
  274. numpy/ctypeslib/__init__.pyi +33 -0
  275. numpy/ctypeslib/_ctypeslib.py +603 -0
  276. numpy/ctypeslib/_ctypeslib.pyi +245 -0
  277. numpy/doc/ufuncs.py +138 -0
  278. numpy/dtypes.py +41 -0
  279. numpy/dtypes.pyi +631 -0
  280. numpy/exceptions.py +247 -0
  281. numpy/exceptions.pyi +27 -0
  282. numpy/f2py/__init__.py +86 -0
  283. numpy/f2py/__init__.pyi +6 -0
  284. numpy/f2py/__main__.py +5 -0
  285. numpy/f2py/__version__.py +1 -0
  286. numpy/f2py/__version__.pyi +1 -0
  287. numpy/f2py/_backends/__init__.py +9 -0
  288. numpy/f2py/_backends/__init__.pyi +5 -0
  289. numpy/f2py/_backends/_backend.py +44 -0
  290. numpy/f2py/_backends/_backend.pyi +46 -0
  291. numpy/f2py/_backends/_distutils.py +76 -0
  292. numpy/f2py/_backends/_distutils.pyi +13 -0
  293. numpy/f2py/_backends/_meson.py +231 -0
  294. numpy/f2py/_backends/_meson.pyi +63 -0
  295. numpy/f2py/_backends/meson.build.template +55 -0
  296. numpy/f2py/_isocbind.py +62 -0
  297. numpy/f2py/_isocbind.pyi +13 -0
  298. numpy/f2py/_src_pyf.py +247 -0
  299. numpy/f2py/_src_pyf.pyi +29 -0
  300. numpy/f2py/auxfuncs.py +1004 -0
  301. numpy/f2py/auxfuncs.pyi +264 -0
  302. numpy/f2py/capi_maps.py +811 -0
  303. numpy/f2py/capi_maps.pyi +33 -0
  304. numpy/f2py/cb_rules.py +665 -0
  305. numpy/f2py/cb_rules.pyi +17 -0
  306. numpy/f2py/cfuncs.py +1563 -0
  307. numpy/f2py/cfuncs.pyi +31 -0
  308. numpy/f2py/common_rules.py +143 -0
  309. numpy/f2py/common_rules.pyi +9 -0
  310. numpy/f2py/crackfortran.py +3725 -0
  311. numpy/f2py/crackfortran.pyi +258 -0
  312. numpy/f2py/diagnose.py +149 -0
  313. numpy/f2py/diagnose.pyi +1 -0
  314. numpy/f2py/f2py2e.py +786 -0
  315. numpy/f2py/f2py2e.pyi +76 -0
  316. numpy/f2py/f90mod_rules.py +269 -0
  317. numpy/f2py/f90mod_rules.pyi +16 -0
  318. numpy/f2py/func2subr.py +329 -0
  319. numpy/f2py/func2subr.pyi +7 -0
  320. numpy/f2py/rules.py +1629 -0
  321. numpy/f2py/rules.pyi +43 -0
  322. numpy/f2py/setup.cfg +3 -0
  323. numpy/f2py/src/fortranobject.c +1436 -0
  324. numpy/f2py/src/fortranobject.h +173 -0
  325. numpy/f2py/symbolic.py +1516 -0
  326. numpy/f2py/symbolic.pyi +221 -0
  327. numpy/f2py/tests/__init__.py +16 -0
  328. numpy/f2py/tests/src/abstract_interface/foo.f90 +34 -0
  329. numpy/f2py/tests/src/abstract_interface/gh18403_mod.f90 +6 -0
  330. numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c +235 -0
  331. numpy/f2py/tests/src/assumed_shape/.f2py_f2cmap +1 -0
  332. numpy/f2py/tests/src/assumed_shape/foo_free.f90 +34 -0
  333. numpy/f2py/tests/src/assumed_shape/foo_mod.f90 +41 -0
  334. numpy/f2py/tests/src/assumed_shape/foo_use.f90 +19 -0
  335. numpy/f2py/tests/src/assumed_shape/precision.f90 +4 -0
  336. numpy/f2py/tests/src/block_docstring/foo.f +6 -0
  337. numpy/f2py/tests/src/callback/foo.f +62 -0
  338. numpy/f2py/tests/src/callback/gh17797.f90 +7 -0
  339. numpy/f2py/tests/src/callback/gh18335.f90 +17 -0
  340. numpy/f2py/tests/src/callback/gh25211.f +10 -0
  341. numpy/f2py/tests/src/callback/gh25211.pyf +18 -0
  342. numpy/f2py/tests/src/callback/gh26681.f90 +18 -0
  343. numpy/f2py/tests/src/cli/gh_22819.pyf +6 -0
  344. numpy/f2py/tests/src/cli/hi77.f +3 -0
  345. numpy/f2py/tests/src/cli/hiworld.f90 +3 -0
  346. numpy/f2py/tests/src/common/block.f +11 -0
  347. numpy/f2py/tests/src/common/gh19161.f90 +10 -0
  348. numpy/f2py/tests/src/crackfortran/accesstype.f90 +13 -0
  349. numpy/f2py/tests/src/crackfortran/common_with_division.f +17 -0
  350. numpy/f2py/tests/src/crackfortran/data_common.f +8 -0
  351. numpy/f2py/tests/src/crackfortran/data_multiplier.f +5 -0
  352. numpy/f2py/tests/src/crackfortran/data_stmts.f90 +20 -0
  353. numpy/f2py/tests/src/crackfortran/data_with_comments.f +8 -0
  354. numpy/f2py/tests/src/crackfortran/foo_deps.f90 +6 -0
  355. numpy/f2py/tests/src/crackfortran/gh15035.f +16 -0
  356. numpy/f2py/tests/src/crackfortran/gh17859.f +12 -0
  357. numpy/f2py/tests/src/crackfortran/gh22648.pyf +7 -0
  358. numpy/f2py/tests/src/crackfortran/gh23533.f +5 -0
  359. numpy/f2py/tests/src/crackfortran/gh23598.f90 +4 -0
  360. numpy/f2py/tests/src/crackfortran/gh23598Warn.f90 +11 -0
  361. numpy/f2py/tests/src/crackfortran/gh23879.f90 +20 -0
  362. numpy/f2py/tests/src/crackfortran/gh27697.f90 +12 -0
  363. numpy/f2py/tests/src/crackfortran/gh2848.f90 +13 -0
  364. numpy/f2py/tests/src/crackfortran/operators.f90 +49 -0
  365. numpy/f2py/tests/src/crackfortran/privatemod.f90 +11 -0
  366. numpy/f2py/tests/src/crackfortran/publicmod.f90 +10 -0
  367. numpy/f2py/tests/src/crackfortran/pubprivmod.f90 +10 -0
  368. numpy/f2py/tests/src/crackfortran/unicode_comment.f90 +4 -0
  369. numpy/f2py/tests/src/f2cmap/.f2py_f2cmap +1 -0
  370. numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90 +9 -0
  371. numpy/f2py/tests/src/isocintrin/isoCtests.f90 +34 -0
  372. numpy/f2py/tests/src/kind/foo.f90 +20 -0
  373. numpy/f2py/tests/src/mixed/foo.f +5 -0
  374. numpy/f2py/tests/src/mixed/foo_fixed.f90 +8 -0
  375. numpy/f2py/tests/src/mixed/foo_free.f90 +8 -0
  376. numpy/f2py/tests/src/modules/gh25337/data.f90 +8 -0
  377. numpy/f2py/tests/src/modules/gh25337/use_data.f90 +6 -0
  378. numpy/f2py/tests/src/modules/gh26920/two_mods_with_no_public_entities.f90 +21 -0
  379. numpy/f2py/tests/src/modules/gh26920/two_mods_with_one_public_routine.f90 +21 -0
  380. numpy/f2py/tests/src/modules/module_data_docstring.f90 +12 -0
  381. numpy/f2py/tests/src/modules/use_modules.f90 +20 -0
  382. numpy/f2py/tests/src/negative_bounds/issue_20853.f90 +7 -0
  383. numpy/f2py/tests/src/parameter/constant_array.f90 +45 -0
  384. numpy/f2py/tests/src/parameter/constant_both.f90 +57 -0
  385. numpy/f2py/tests/src/parameter/constant_compound.f90 +15 -0
  386. numpy/f2py/tests/src/parameter/constant_integer.f90 +22 -0
  387. numpy/f2py/tests/src/parameter/constant_non_compound.f90 +23 -0
  388. numpy/f2py/tests/src/parameter/constant_real.f90 +23 -0
  389. numpy/f2py/tests/src/quoted_character/foo.f +14 -0
  390. numpy/f2py/tests/src/regression/AB.inc +1 -0
  391. numpy/f2py/tests/src/regression/assignOnlyModule.f90 +25 -0
  392. numpy/f2py/tests/src/regression/datonly.f90 +17 -0
  393. numpy/f2py/tests/src/regression/f77comments.f +26 -0
  394. numpy/f2py/tests/src/regression/f77fixedform.f95 +5 -0
  395. numpy/f2py/tests/src/regression/f90continuation.f90 +9 -0
  396. numpy/f2py/tests/src/regression/incfile.f90 +5 -0
  397. numpy/f2py/tests/src/regression/inout.f90 +9 -0
  398. numpy/f2py/tests/src/regression/lower_f2py_fortran.f90 +5 -0
  399. numpy/f2py/tests/src/regression/mod_derived_types.f90 +23 -0
  400. numpy/f2py/tests/src/return_character/foo77.f +45 -0
  401. numpy/f2py/tests/src/return_character/foo90.f90 +48 -0
  402. numpy/f2py/tests/src/return_complex/foo77.f +45 -0
  403. numpy/f2py/tests/src/return_complex/foo90.f90 +48 -0
  404. numpy/f2py/tests/src/return_integer/foo77.f +56 -0
  405. numpy/f2py/tests/src/return_integer/foo90.f90 +59 -0
  406. numpy/f2py/tests/src/return_logical/foo77.f +56 -0
  407. numpy/f2py/tests/src/return_logical/foo90.f90 +59 -0
  408. numpy/f2py/tests/src/return_real/foo77.f +45 -0
  409. numpy/f2py/tests/src/return_real/foo90.f90 +48 -0
  410. numpy/f2py/tests/src/routines/funcfortranname.f +5 -0
  411. numpy/f2py/tests/src/routines/funcfortranname.pyf +11 -0
  412. numpy/f2py/tests/src/routines/subrout.f +4 -0
  413. numpy/f2py/tests/src/routines/subrout.pyf +10 -0
  414. numpy/f2py/tests/src/size/foo.f90 +44 -0
  415. numpy/f2py/tests/src/string/char.f90 +29 -0
  416. numpy/f2py/tests/src/string/fixed_string.f90 +34 -0
  417. numpy/f2py/tests/src/string/gh24008.f +8 -0
  418. numpy/f2py/tests/src/string/gh24662.f90 +7 -0
  419. numpy/f2py/tests/src/string/gh25286.f90 +14 -0
  420. numpy/f2py/tests/src/string/gh25286.pyf +12 -0
  421. numpy/f2py/tests/src/string/gh25286_bc.pyf +12 -0
  422. numpy/f2py/tests/src/string/scalar_string.f90 +9 -0
  423. numpy/f2py/tests/src/string/string.f +12 -0
  424. numpy/f2py/tests/src/value_attrspec/gh21665.f90 +9 -0
  425. numpy/f2py/tests/test_abstract_interface.py +26 -0
  426. numpy/f2py/tests/test_array_from_pyobj.py +678 -0
  427. numpy/f2py/tests/test_assumed_shape.py +50 -0
  428. numpy/f2py/tests/test_block_docstring.py +20 -0
  429. numpy/f2py/tests/test_callback.py +263 -0
  430. numpy/f2py/tests/test_character.py +641 -0
  431. numpy/f2py/tests/test_common.py +23 -0
  432. numpy/f2py/tests/test_crackfortran.py +421 -0
  433. numpy/f2py/tests/test_data.py +71 -0
  434. numpy/f2py/tests/test_docs.py +64 -0
  435. numpy/f2py/tests/test_f2cmap.py +17 -0
  436. numpy/f2py/tests/test_f2py2e.py +964 -0
  437. numpy/f2py/tests/test_isoc.py +56 -0
  438. numpy/f2py/tests/test_kind.py +53 -0
  439. numpy/f2py/tests/test_mixed.py +35 -0
  440. numpy/f2py/tests/test_modules.py +83 -0
  441. numpy/f2py/tests/test_parameter.py +129 -0
  442. numpy/f2py/tests/test_pyf_src.py +43 -0
  443. numpy/f2py/tests/test_quoted_character.py +18 -0
  444. numpy/f2py/tests/test_regression.py +187 -0
  445. numpy/f2py/tests/test_return_character.py +48 -0
  446. numpy/f2py/tests/test_return_complex.py +67 -0
  447. numpy/f2py/tests/test_return_integer.py +55 -0
  448. numpy/f2py/tests/test_return_logical.py +65 -0
  449. numpy/f2py/tests/test_return_real.py +109 -0
  450. numpy/f2py/tests/test_routines.py +29 -0
  451. numpy/f2py/tests/test_semicolon_split.py +75 -0
  452. numpy/f2py/tests/test_size.py +45 -0
  453. numpy/f2py/tests/test_string.py +100 -0
  454. numpy/f2py/tests/test_symbolic.py +495 -0
  455. numpy/f2py/tests/test_value_attrspec.py +15 -0
  456. numpy/f2py/tests/util.py +442 -0
  457. numpy/f2py/use_rules.py +99 -0
  458. numpy/f2py/use_rules.pyi +9 -0
  459. numpy/fft/__init__.py +215 -0
  460. numpy/fft/__init__.pyi +43 -0
  461. numpy/fft/_helper.py +235 -0
  462. numpy/fft/_helper.pyi +45 -0
  463. numpy/fft/_pocketfft.py +1693 -0
  464. numpy/fft/_pocketfft.pyi +138 -0
  465. numpy/fft/_pocketfft_umath.cpython-313-darwin.so +0 -0
  466. numpy/fft/helper.py +17 -0
  467. numpy/fft/helper.pyi +22 -0
  468. numpy/fft/tests/__init__.py +0 -0
  469. numpy/fft/tests/test_helper.py +167 -0
  470. numpy/fft/tests/test_pocketfft.py +589 -0
  471. numpy/lib/__init__.py +97 -0
  472. numpy/lib/__init__.pyi +44 -0
  473. numpy/lib/_array_utils_impl.py +62 -0
  474. numpy/lib/_array_utils_impl.pyi +26 -0
  475. numpy/lib/_arraypad_impl.py +890 -0
  476. numpy/lib/_arraypad_impl.pyi +89 -0
  477. numpy/lib/_arraysetops_impl.py +1260 -0
  478. numpy/lib/_arraysetops_impl.pyi +468 -0
  479. numpy/lib/_arrayterator_impl.py +224 -0
  480. numpy/lib/_arrayterator_impl.pyi +46 -0
  481. numpy/lib/_datasource.py +700 -0
  482. numpy/lib/_datasource.pyi +31 -0
  483. numpy/lib/_format_impl.py +1036 -0
  484. numpy/lib/_format_impl.pyi +26 -0
  485. numpy/lib/_function_base_impl.py +5844 -0
  486. numpy/lib/_function_base_impl.pyi +1164 -0
  487. numpy/lib/_histograms_impl.py +1085 -0
  488. numpy/lib/_histograms_impl.pyi +50 -0
  489. numpy/lib/_index_tricks_impl.py +1067 -0
  490. numpy/lib/_index_tricks_impl.pyi +208 -0
  491. numpy/lib/_iotools.py +900 -0
  492. numpy/lib/_iotools.pyi +114 -0
  493. numpy/lib/_nanfunctions_impl.py +2024 -0
  494. numpy/lib/_nanfunctions_impl.pyi +52 -0
  495. numpy/lib/_npyio_impl.py +2596 -0
  496. numpy/lib/_npyio_impl.pyi +301 -0
  497. numpy/lib/_polynomial_impl.py +1465 -0
  498. numpy/lib/_polynomial_impl.pyi +318 -0
  499. numpy/lib/_scimath_impl.py +642 -0
  500. numpy/lib/_scimath_impl.pyi +93 -0
  501. numpy/lib/_shape_base_impl.py +1301 -0
  502. numpy/lib/_shape_base_impl.pyi +235 -0
  503. numpy/lib/_stride_tricks_impl.py +549 -0
  504. numpy/lib/_stride_tricks_impl.pyi +74 -0
  505. numpy/lib/_twodim_base_impl.py +1201 -0
  506. numpy/lib/_twodim_base_impl.pyi +438 -0
  507. numpy/lib/_type_check_impl.py +699 -0
  508. numpy/lib/_type_check_impl.pyi +350 -0
  509. numpy/lib/_ufunclike_impl.py +207 -0
  510. numpy/lib/_ufunclike_impl.pyi +67 -0
  511. numpy/lib/_user_array_impl.py +299 -0
  512. numpy/lib/_user_array_impl.pyi +225 -0
  513. numpy/lib/_utils_impl.py +784 -0
  514. numpy/lib/_utils_impl.pyi +10 -0
  515. numpy/lib/_version.py +154 -0
  516. numpy/lib/_version.pyi +17 -0
  517. numpy/lib/array_utils.py +7 -0
  518. numpy/lib/array_utils.pyi +12 -0
  519. numpy/lib/format.py +24 -0
  520. numpy/lib/format.pyi +66 -0
  521. numpy/lib/introspect.py +95 -0
  522. numpy/lib/introspect.pyi +3 -0
  523. numpy/lib/mixins.py +180 -0
  524. numpy/lib/mixins.pyi +77 -0
  525. numpy/lib/npyio.py +1 -0
  526. numpy/lib/npyio.pyi +9 -0
  527. numpy/lib/recfunctions.py +1681 -0
  528. numpy/lib/recfunctions.pyi +435 -0
  529. numpy/lib/scimath.py +13 -0
  530. numpy/lib/scimath.pyi +30 -0
  531. numpy/lib/stride_tricks.py +1 -0
  532. numpy/lib/stride_tricks.pyi +6 -0
  533. numpy/lib/tests/__init__.py +0 -0
  534. numpy/lib/tests/data/py2-np0-objarr.npy +0 -0
  535. numpy/lib/tests/data/py2-objarr.npy +0 -0
  536. numpy/lib/tests/data/py2-objarr.npz +0 -0
  537. numpy/lib/tests/data/py3-objarr.npy +0 -0
  538. numpy/lib/tests/data/py3-objarr.npz +0 -0
  539. numpy/lib/tests/data/python3.npy +0 -0
  540. numpy/lib/tests/data/win64python2.npy +0 -0
  541. numpy/lib/tests/test__datasource.py +352 -0
  542. numpy/lib/tests/test__iotools.py +360 -0
  543. numpy/lib/tests/test__version.py +64 -0
  544. numpy/lib/tests/test_array_utils.py +32 -0
  545. numpy/lib/tests/test_arraypad.py +1415 -0
  546. numpy/lib/tests/test_arraysetops.py +1074 -0
  547. numpy/lib/tests/test_arrayterator.py +46 -0
  548. numpy/lib/tests/test_format.py +1054 -0
  549. numpy/lib/tests/test_function_base.py +4573 -0
  550. numpy/lib/tests/test_histograms.py +855 -0
  551. numpy/lib/tests/test_index_tricks.py +573 -0
  552. numpy/lib/tests/test_io.py +2848 -0
  553. numpy/lib/tests/test_loadtxt.py +1101 -0
  554. numpy/lib/tests/test_mixins.py +215 -0
  555. numpy/lib/tests/test_nanfunctions.py +1438 -0
  556. numpy/lib/tests/test_packbits.py +376 -0
  557. numpy/lib/tests/test_polynomial.py +320 -0
  558. numpy/lib/tests/test_recfunctions.py +1052 -0
  559. numpy/lib/tests/test_regression.py +231 -0
  560. numpy/lib/tests/test_shape_base.py +813 -0
  561. numpy/lib/tests/test_stride_tricks.py +656 -0
  562. numpy/lib/tests/test_twodim_base.py +559 -0
  563. numpy/lib/tests/test_type_check.py +473 -0
  564. numpy/lib/tests/test_ufunclike.py +97 -0
  565. numpy/lib/tests/test_utils.py +80 -0
  566. numpy/lib/user_array.py +1 -0
  567. numpy/lib/user_array.pyi +1 -0
  568. numpy/linalg/__init__.py +98 -0
  569. numpy/linalg/__init__.pyi +73 -0
  570. numpy/linalg/_linalg.py +3682 -0
  571. numpy/linalg/_linalg.pyi +475 -0
  572. numpy/linalg/_umath_linalg.cpython-313-darwin.so +0 -0
  573. numpy/linalg/_umath_linalg.pyi +61 -0
  574. numpy/linalg/lapack_lite.cpython-313-darwin.so +0 -0
  575. numpy/linalg/lapack_lite.pyi +141 -0
  576. numpy/linalg/linalg.py +17 -0
  577. numpy/linalg/linalg.pyi +69 -0
  578. numpy/linalg/tests/__init__.py +0 -0
  579. numpy/linalg/tests/test_deprecations.py +20 -0
  580. numpy/linalg/tests/test_linalg.py +2443 -0
  581. numpy/linalg/tests/test_regression.py +181 -0
  582. numpy/ma/API_CHANGES.txt +135 -0
  583. numpy/ma/LICENSE +24 -0
  584. numpy/ma/README.rst +236 -0
  585. numpy/ma/__init__.py +53 -0
  586. numpy/ma/__init__.pyi +458 -0
  587. numpy/ma/core.py +8933 -0
  588. numpy/ma/core.pyi +1462 -0
  589. numpy/ma/extras.py +2344 -0
  590. numpy/ma/extras.pyi +138 -0
  591. numpy/ma/mrecords.py +773 -0
  592. numpy/ma/mrecords.pyi +96 -0
  593. numpy/ma/tests/__init__.py +0 -0
  594. numpy/ma/tests/test_arrayobject.py +40 -0
  595. numpy/ma/tests/test_core.py +5886 -0
  596. numpy/ma/tests/test_deprecations.py +87 -0
  597. numpy/ma/tests/test_extras.py +1998 -0
  598. numpy/ma/tests/test_mrecords.py +497 -0
  599. numpy/ma/tests/test_old_ma.py +942 -0
  600. numpy/ma/tests/test_regression.py +100 -0
  601. numpy/ma/tests/test_subclassing.py +469 -0
  602. numpy/ma/testutils.py +294 -0
  603. numpy/matlib.py +380 -0
  604. numpy/matlib.pyi +582 -0
  605. numpy/matrixlib/__init__.py +12 -0
  606. numpy/matrixlib/__init__.pyi +5 -0
  607. numpy/matrixlib/defmatrix.py +1119 -0
  608. numpy/matrixlib/defmatrix.pyi +17 -0
  609. numpy/matrixlib/tests/__init__.py +0 -0
  610. numpy/matrixlib/tests/test_defmatrix.py +455 -0
  611. numpy/matrixlib/tests/test_interaction.py +360 -0
  612. numpy/matrixlib/tests/test_masked_matrix.py +240 -0
  613. numpy/matrixlib/tests/test_matrix_linalg.py +105 -0
  614. numpy/matrixlib/tests/test_multiarray.py +17 -0
  615. numpy/matrixlib/tests/test_numeric.py +18 -0
  616. numpy/matrixlib/tests/test_regression.py +31 -0
  617. numpy/polynomial/__init__.py +187 -0
  618. numpy/polynomial/__init__.pyi +25 -0
  619. numpy/polynomial/_polybase.py +1191 -0
  620. numpy/polynomial/_polybase.pyi +285 -0
  621. numpy/polynomial/_polytypes.pyi +892 -0
  622. numpy/polynomial/chebyshev.py +2003 -0
  623. numpy/polynomial/chebyshev.pyi +181 -0
  624. numpy/polynomial/hermite.py +1740 -0
  625. numpy/polynomial/hermite.pyi +107 -0
  626. numpy/polynomial/hermite_e.py +1642 -0
  627. numpy/polynomial/hermite_e.pyi +107 -0
  628. numpy/polynomial/laguerre.py +1675 -0
  629. numpy/polynomial/laguerre.pyi +100 -0
  630. numpy/polynomial/legendre.py +1605 -0
  631. numpy/polynomial/legendre.pyi +100 -0
  632. numpy/polynomial/polynomial.py +1616 -0
  633. numpy/polynomial/polynomial.pyi +89 -0
  634. numpy/polynomial/polyutils.py +759 -0
  635. numpy/polynomial/polyutils.pyi +423 -0
  636. numpy/polynomial/tests/__init__.py +0 -0
  637. numpy/polynomial/tests/test_chebyshev.py +623 -0
  638. numpy/polynomial/tests/test_classes.py +618 -0
  639. numpy/polynomial/tests/test_hermite.py +558 -0
  640. numpy/polynomial/tests/test_hermite_e.py +559 -0
  641. numpy/polynomial/tests/test_laguerre.py +540 -0
  642. numpy/polynomial/tests/test_legendre.py +571 -0
  643. numpy/polynomial/tests/test_polynomial.py +669 -0
  644. numpy/polynomial/tests/test_polyutils.py +128 -0
  645. numpy/polynomial/tests/test_printing.py +555 -0
  646. numpy/polynomial/tests/test_symbol.py +217 -0
  647. numpy/py.typed +0 -0
  648. numpy/random/LICENSE.md +71 -0
  649. numpy/random/__init__.pxd +14 -0
  650. numpy/random/__init__.py +213 -0
  651. numpy/random/__init__.pyi +124 -0
  652. numpy/random/_bounded_integers.cpython-313-darwin.so +0 -0
  653. numpy/random/_bounded_integers.pxd +29 -0
  654. numpy/random/_bounded_integers.pyi +1 -0
  655. numpy/random/_common.cpython-313-darwin.so +0 -0
  656. numpy/random/_common.pxd +107 -0
  657. numpy/random/_common.pyi +16 -0
  658. numpy/random/_examples/cffi/extending.py +44 -0
  659. numpy/random/_examples/cffi/parse.py +53 -0
  660. numpy/random/_examples/cython/extending.pyx +77 -0
  661. numpy/random/_examples/cython/extending_distributions.pyx +118 -0
  662. numpy/random/_examples/cython/meson.build +53 -0
  663. numpy/random/_examples/numba/extending.py +86 -0
  664. numpy/random/_examples/numba/extending_distributions.py +67 -0
  665. numpy/random/_generator.cpython-313-darwin.so +0 -0
  666. numpy/random/_generator.pyi +861 -0
  667. numpy/random/_mt19937.cpython-313-darwin.so +0 -0
  668. numpy/random/_mt19937.pyi +25 -0
  669. numpy/random/_pcg64.cpython-313-darwin.so +0 -0
  670. numpy/random/_pcg64.pyi +44 -0
  671. numpy/random/_philox.cpython-313-darwin.so +0 -0
  672. numpy/random/_philox.pyi +39 -0
  673. numpy/random/_pickle.py +88 -0
  674. numpy/random/_pickle.pyi +43 -0
  675. numpy/random/_sfc64.cpython-313-darwin.so +0 -0
  676. numpy/random/_sfc64.pyi +28 -0
  677. numpy/random/bit_generator.cpython-313-darwin.so +0 -0
  678. numpy/random/bit_generator.pxd +35 -0
  679. numpy/random/bit_generator.pyi +124 -0
  680. numpy/random/c_distributions.pxd +119 -0
  681. numpy/random/lib/libnpyrandom.a +0 -0
  682. numpy/random/mtrand.cpython-313-darwin.so +0 -0
  683. numpy/random/mtrand.pyi +703 -0
  684. numpy/random/tests/__init__.py +0 -0
  685. numpy/random/tests/data/__init__.py +0 -0
  686. numpy/random/tests/data/generator_pcg64_np121.pkl.gz +0 -0
  687. numpy/random/tests/data/generator_pcg64_np126.pkl.gz +0 -0
  688. numpy/random/tests/data/mt19937-testset-1.csv +1001 -0
  689. numpy/random/tests/data/mt19937-testset-2.csv +1001 -0
  690. numpy/random/tests/data/pcg64-testset-1.csv +1001 -0
  691. numpy/random/tests/data/pcg64-testset-2.csv +1001 -0
  692. numpy/random/tests/data/pcg64dxsm-testset-1.csv +1001 -0
  693. numpy/random/tests/data/pcg64dxsm-testset-2.csv +1001 -0
  694. numpy/random/tests/data/philox-testset-1.csv +1001 -0
  695. numpy/random/tests/data/philox-testset-2.csv +1001 -0
  696. numpy/random/tests/data/sfc64-testset-1.csv +1001 -0
  697. numpy/random/tests/data/sfc64-testset-2.csv +1001 -0
  698. numpy/random/tests/data/sfc64_np126.pkl.gz +0 -0
  699. numpy/random/tests/test_direct.py +592 -0
  700. numpy/random/tests/test_extending.py +127 -0
  701. numpy/random/tests/test_generator_mt19937.py +2809 -0
  702. numpy/random/tests/test_generator_mt19937_regressions.py +207 -0
  703. numpy/random/tests/test_random.py +1757 -0
  704. numpy/random/tests/test_randomstate.py +2130 -0
  705. numpy/random/tests/test_randomstate_regression.py +217 -0
  706. numpy/random/tests/test_regression.py +152 -0
  707. numpy/random/tests/test_seed_sequence.py +79 -0
  708. numpy/random/tests/test_smoke.py +819 -0
  709. numpy/rec/__init__.py +2 -0
  710. numpy/rec/__init__.pyi +23 -0
  711. numpy/strings/__init__.py +2 -0
  712. numpy/strings/__init__.pyi +97 -0
  713. numpy/testing/__init__.py +22 -0
  714. numpy/testing/__init__.pyi +102 -0
  715. numpy/testing/_private/__init__.py +0 -0
  716. numpy/testing/_private/__init__.pyi +0 -0
  717. numpy/testing/_private/extbuild.py +250 -0
  718. numpy/testing/_private/extbuild.pyi +25 -0
  719. numpy/testing/_private/utils.py +2752 -0
  720. numpy/testing/_private/utils.pyi +499 -0
  721. numpy/testing/overrides.py +84 -0
  722. numpy/testing/overrides.pyi +11 -0
  723. numpy/testing/print_coercion_tables.py +207 -0
  724. numpy/testing/print_coercion_tables.pyi +27 -0
  725. numpy/testing/tests/__init__.py +0 -0
  726. numpy/testing/tests/test_utils.py +1917 -0
  727. numpy/tests/__init__.py +0 -0
  728. numpy/tests/test__all__.py +10 -0
  729. numpy/tests/test_configtool.py +48 -0
  730. numpy/tests/test_ctypeslib.py +377 -0
  731. numpy/tests/test_lazyloading.py +38 -0
  732. numpy/tests/test_matlib.py +59 -0
  733. numpy/tests/test_numpy_config.py +46 -0
  734. numpy/tests/test_numpy_version.py +54 -0
  735. numpy/tests/test_public_api.py +806 -0
  736. numpy/tests/test_reloading.py +74 -0
  737. numpy/tests/test_scripts.py +49 -0
  738. numpy/tests/test_warnings.py +78 -0
  739. numpy/typing/__init__.py +201 -0
  740. numpy/typing/mypy_plugin.py +195 -0
  741. numpy/typing/tests/__init__.py +0 -0
  742. numpy/typing/tests/data/fail/arithmetic.pyi +126 -0
  743. numpy/typing/tests/data/fail/array_constructors.pyi +34 -0
  744. numpy/typing/tests/data/fail/array_like.pyi +15 -0
  745. numpy/typing/tests/data/fail/array_pad.pyi +6 -0
  746. numpy/typing/tests/data/fail/arrayprint.pyi +16 -0
  747. numpy/typing/tests/data/fail/arrayterator.pyi +14 -0
  748. numpy/typing/tests/data/fail/bitwise_ops.pyi +17 -0
  749. numpy/typing/tests/data/fail/char.pyi +65 -0
  750. numpy/typing/tests/data/fail/chararray.pyi +62 -0
  751. numpy/typing/tests/data/fail/comparisons.pyi +27 -0
  752. numpy/typing/tests/data/fail/constants.pyi +3 -0
  753. numpy/typing/tests/data/fail/datasource.pyi +15 -0
  754. numpy/typing/tests/data/fail/dtype.pyi +17 -0
  755. numpy/typing/tests/data/fail/einsumfunc.pyi +12 -0
  756. numpy/typing/tests/data/fail/flatiter.pyi +20 -0
  757. numpy/typing/tests/data/fail/fromnumeric.pyi +148 -0
  758. numpy/typing/tests/data/fail/histograms.pyi +12 -0
  759. numpy/typing/tests/data/fail/index_tricks.pyi +14 -0
  760. numpy/typing/tests/data/fail/lib_function_base.pyi +62 -0
  761. numpy/typing/tests/data/fail/lib_polynomial.pyi +29 -0
  762. numpy/typing/tests/data/fail/lib_utils.pyi +3 -0
  763. numpy/typing/tests/data/fail/lib_version.pyi +6 -0
  764. numpy/typing/tests/data/fail/linalg.pyi +48 -0
  765. numpy/typing/tests/data/fail/ma.pyi +143 -0
  766. numpy/typing/tests/data/fail/memmap.pyi +5 -0
  767. numpy/typing/tests/data/fail/modules.pyi +17 -0
  768. numpy/typing/tests/data/fail/multiarray.pyi +52 -0
  769. numpy/typing/tests/data/fail/ndarray.pyi +11 -0
  770. numpy/typing/tests/data/fail/ndarray_misc.pyi +36 -0
  771. numpy/typing/tests/data/fail/nditer.pyi +8 -0
  772. numpy/typing/tests/data/fail/nested_sequence.pyi +16 -0
  773. numpy/typing/tests/data/fail/npyio.pyi +24 -0
  774. numpy/typing/tests/data/fail/numerictypes.pyi +5 -0
  775. numpy/typing/tests/data/fail/random.pyi +62 -0
  776. numpy/typing/tests/data/fail/rec.pyi +17 -0
  777. numpy/typing/tests/data/fail/scalars.pyi +87 -0
  778. numpy/typing/tests/data/fail/shape.pyi +6 -0
  779. numpy/typing/tests/data/fail/shape_base.pyi +8 -0
  780. numpy/typing/tests/data/fail/stride_tricks.pyi +9 -0
  781. numpy/typing/tests/data/fail/strings.pyi +52 -0
  782. numpy/typing/tests/data/fail/testing.pyi +28 -0
  783. numpy/typing/tests/data/fail/twodim_base.pyi +32 -0
  784. numpy/typing/tests/data/fail/type_check.pyi +13 -0
  785. numpy/typing/tests/data/fail/ufunc_config.pyi +21 -0
  786. numpy/typing/tests/data/fail/ufunclike.pyi +21 -0
  787. numpy/typing/tests/data/fail/ufuncs.pyi +17 -0
  788. numpy/typing/tests/data/fail/warnings_and_errors.pyi +5 -0
  789. numpy/typing/tests/data/misc/extended_precision.pyi +9 -0
  790. numpy/typing/tests/data/mypy.ini +9 -0
  791. numpy/typing/tests/data/pass/arithmetic.py +612 -0
  792. numpy/typing/tests/data/pass/array_constructors.py +137 -0
  793. numpy/typing/tests/data/pass/array_like.py +43 -0
  794. numpy/typing/tests/data/pass/arrayprint.py +37 -0
  795. numpy/typing/tests/data/pass/arrayterator.py +27 -0
  796. numpy/typing/tests/data/pass/bitwise_ops.py +131 -0
  797. numpy/typing/tests/data/pass/comparisons.py +315 -0
  798. numpy/typing/tests/data/pass/dtype.py +57 -0
  799. numpy/typing/tests/data/pass/einsumfunc.py +36 -0
  800. numpy/typing/tests/data/pass/flatiter.py +19 -0
  801. numpy/typing/tests/data/pass/fromnumeric.py +272 -0
  802. numpy/typing/tests/data/pass/index_tricks.py +60 -0
  803. numpy/typing/tests/data/pass/lib_user_array.py +22 -0
  804. numpy/typing/tests/data/pass/lib_utils.py +19 -0
  805. numpy/typing/tests/data/pass/lib_version.py +18 -0
  806. numpy/typing/tests/data/pass/literal.py +51 -0
  807. numpy/typing/tests/data/pass/ma.py +174 -0
  808. numpy/typing/tests/data/pass/mod.py +149 -0
  809. numpy/typing/tests/data/pass/modules.py +45 -0
  810. numpy/typing/tests/data/pass/multiarray.py +76 -0
  811. numpy/typing/tests/data/pass/ndarray_conversion.py +87 -0
  812. numpy/typing/tests/data/pass/ndarray_misc.py +203 -0
  813. numpy/typing/tests/data/pass/ndarray_shape_manipulation.py +47 -0
  814. numpy/typing/tests/data/pass/nditer.py +4 -0
  815. numpy/typing/tests/data/pass/numeric.py +95 -0
  816. numpy/typing/tests/data/pass/numerictypes.py +17 -0
  817. numpy/typing/tests/data/pass/random.py +1497 -0
  818. numpy/typing/tests/data/pass/recfunctions.py +161 -0
  819. numpy/typing/tests/data/pass/scalars.py +248 -0
  820. numpy/typing/tests/data/pass/shape.py +19 -0
  821. numpy/typing/tests/data/pass/simple.py +168 -0
  822. numpy/typing/tests/data/pass/simple_py3.py +6 -0
  823. numpy/typing/tests/data/pass/ufunc_config.py +64 -0
  824. numpy/typing/tests/data/pass/ufunclike.py +47 -0
  825. numpy/typing/tests/data/pass/ufuncs.py +16 -0
  826. numpy/typing/tests/data/pass/warnings_and_errors.py +6 -0
  827. numpy/typing/tests/data/reveal/arithmetic.pyi +720 -0
  828. numpy/typing/tests/data/reveal/array_api_info.pyi +70 -0
  829. numpy/typing/tests/data/reveal/array_constructors.pyi +249 -0
  830. numpy/typing/tests/data/reveal/arraypad.pyi +22 -0
  831. numpy/typing/tests/data/reveal/arrayprint.pyi +25 -0
  832. numpy/typing/tests/data/reveal/arraysetops.pyi +74 -0
  833. numpy/typing/tests/data/reveal/arrayterator.pyi +27 -0
  834. numpy/typing/tests/data/reveal/bitwise_ops.pyi +167 -0
  835. numpy/typing/tests/data/reveal/char.pyi +224 -0
  836. numpy/typing/tests/data/reveal/chararray.pyi +137 -0
  837. numpy/typing/tests/data/reveal/comparisons.pyi +264 -0
  838. numpy/typing/tests/data/reveal/constants.pyi +14 -0
  839. numpy/typing/tests/data/reveal/ctypeslib.pyi +81 -0
  840. numpy/typing/tests/data/reveal/datasource.pyi +23 -0
  841. numpy/typing/tests/data/reveal/dtype.pyi +136 -0
  842. numpy/typing/tests/data/reveal/einsumfunc.pyi +39 -0
  843. numpy/typing/tests/data/reveal/emath.pyi +54 -0
  844. numpy/typing/tests/data/reveal/fft.pyi +37 -0
  845. numpy/typing/tests/data/reveal/flatiter.pyi +47 -0
  846. numpy/typing/tests/data/reveal/fromnumeric.pyi +347 -0
  847. numpy/typing/tests/data/reveal/getlimits.pyi +51 -0
  848. numpy/typing/tests/data/reveal/histograms.pyi +25 -0
  849. numpy/typing/tests/data/reveal/index_tricks.pyi +70 -0
  850. numpy/typing/tests/data/reveal/lib_function_base.pyi +213 -0
  851. numpy/typing/tests/data/reveal/lib_polynomial.pyi +144 -0
  852. numpy/typing/tests/data/reveal/lib_utils.pyi +17 -0
  853. numpy/typing/tests/data/reveal/lib_version.pyi +20 -0
  854. numpy/typing/tests/data/reveal/linalg.pyi +132 -0
  855. numpy/typing/tests/data/reveal/ma.pyi +369 -0
  856. numpy/typing/tests/data/reveal/matrix.pyi +73 -0
  857. numpy/typing/tests/data/reveal/memmap.pyi +19 -0
  858. numpy/typing/tests/data/reveal/mod.pyi +179 -0
  859. numpy/typing/tests/data/reveal/modules.pyi +51 -0
  860. numpy/typing/tests/data/reveal/multiarray.pyi +194 -0
  861. numpy/typing/tests/data/reveal/nbit_base_example.pyi +21 -0
  862. numpy/typing/tests/data/reveal/ndarray_assignability.pyi +77 -0
  863. numpy/typing/tests/data/reveal/ndarray_conversion.pyi +85 -0
  864. numpy/typing/tests/data/reveal/ndarray_misc.pyi +247 -0
  865. numpy/typing/tests/data/reveal/ndarray_shape_manipulation.pyi +39 -0
  866. numpy/typing/tests/data/reveal/nditer.pyi +49 -0
  867. numpy/typing/tests/data/reveal/nested_sequence.pyi +25 -0
  868. numpy/typing/tests/data/reveal/npyio.pyi +83 -0
  869. numpy/typing/tests/data/reveal/numeric.pyi +134 -0
  870. numpy/typing/tests/data/reveal/numerictypes.pyi +16 -0
  871. numpy/typing/tests/data/reveal/polynomial_polybase.pyi +220 -0
  872. numpy/typing/tests/data/reveal/polynomial_polyutils.pyi +219 -0
  873. numpy/typing/tests/data/reveal/polynomial_series.pyi +138 -0
  874. numpy/typing/tests/data/reveal/random.pyi +1546 -0
  875. numpy/typing/tests/data/reveal/rec.pyi +171 -0
  876. numpy/typing/tests/data/reveal/scalars.pyi +191 -0
  877. numpy/typing/tests/data/reveal/shape.pyi +13 -0
  878. numpy/typing/tests/data/reveal/shape_base.pyi +52 -0
  879. numpy/typing/tests/data/reveal/stride_tricks.pyi +27 -0
  880. numpy/typing/tests/data/reveal/strings.pyi +196 -0
  881. numpy/typing/tests/data/reveal/testing.pyi +198 -0
  882. numpy/typing/tests/data/reveal/twodim_base.pyi +145 -0
  883. numpy/typing/tests/data/reveal/type_check.pyi +67 -0
  884. numpy/typing/tests/data/reveal/ufunc_config.pyi +30 -0
  885. numpy/typing/tests/data/reveal/ufunclike.pyi +31 -0
  886. numpy/typing/tests/data/reveal/ufuncs.pyi +123 -0
  887. numpy/typing/tests/data/reveal/warnings_and_errors.pyi +11 -0
  888. numpy/typing/tests/test_isfile.py +32 -0
  889. numpy/typing/tests/test_runtime.py +102 -0
  890. numpy/typing/tests/test_typing.py +205 -0
  891. numpy/version.py +11 -0
  892. numpy/version.pyi +18 -0
  893. numpy-2.3.5.dist-info/LICENSE.txt +971 -0
  894. numpy-2.3.5.dist-info/METADATA +1093 -0
  895. numpy-2.3.5.dist-info/RECORD +897 -0
  896. numpy-2.3.5.dist-info/WHEEL +6 -0
  897. numpy-2.3.5.dist-info/entry_points.txt +13 -0
@@ -0,0 +1,1616 @@
1
+ """
2
+ =================================================
3
+ Power Series (:mod:`numpy.polynomial.polynomial`)
4
+ =================================================
5
+
6
+ This module provides a number of objects (mostly functions) useful for
7
+ dealing with polynomials, including a `Polynomial` class that
8
+ encapsulates the usual arithmetic operations. (General information
9
+ on how this module represents and works with polynomial objects is in
10
+ the docstring for its "parent" sub-package, `numpy.polynomial`).
11
+
12
+ Classes
13
+ -------
14
+ .. autosummary::
15
+ :toctree: generated/
16
+
17
+ Polynomial
18
+
19
+ Constants
20
+ ---------
21
+ .. autosummary::
22
+ :toctree: generated/
23
+
24
+ polydomain
25
+ polyzero
26
+ polyone
27
+ polyx
28
+
29
+ Arithmetic
30
+ ----------
31
+ .. autosummary::
32
+ :toctree: generated/
33
+
34
+ polyadd
35
+ polysub
36
+ polymulx
37
+ polymul
38
+ polydiv
39
+ polypow
40
+ polyval
41
+ polyval2d
42
+ polyval3d
43
+ polygrid2d
44
+ polygrid3d
45
+
46
+ Calculus
47
+ --------
48
+ .. autosummary::
49
+ :toctree: generated/
50
+
51
+ polyder
52
+ polyint
53
+
54
+ Misc Functions
55
+ --------------
56
+ .. autosummary::
57
+ :toctree: generated/
58
+
59
+ polyfromroots
60
+ polyroots
61
+ polyvalfromroots
62
+ polyvander
63
+ polyvander2d
64
+ polyvander3d
65
+ polycompanion
66
+ polyfit
67
+ polytrim
68
+ polyline
69
+
70
+ See Also
71
+ --------
72
+ `numpy.polynomial`
73
+
74
+ """
75
+ __all__ = [
76
+ 'polyzero', 'polyone', 'polyx', 'polydomain', 'polyline', 'polyadd',
77
+ 'polysub', 'polymulx', 'polymul', 'polydiv', 'polypow', 'polyval',
78
+ 'polyvalfromroots', 'polyder', 'polyint', 'polyfromroots', 'polyvander',
79
+ 'polyfit', 'polytrim', 'polyroots', 'Polynomial', 'polyval2d', 'polyval3d',
80
+ 'polygrid2d', 'polygrid3d', 'polyvander2d', 'polyvander3d',
81
+ 'polycompanion']
82
+
83
+ import numpy as np
84
+ import numpy.linalg as la
85
+ from numpy.lib.array_utils import normalize_axis_index
86
+
87
+ from . import polyutils as pu
88
+ from ._polybase import ABCPolyBase
89
+
90
+ polytrim = pu.trimcoef
91
+
92
+ #
93
+ # These are constant arrays are of integer type so as to be compatible
94
+ # with the widest range of other types, such as Decimal.
95
+ #
96
+
97
+ # Polynomial default domain.
98
+ polydomain = np.array([-1., 1.])
99
+
100
+ # Polynomial coefficients representing zero.
101
+ polyzero = np.array([0])
102
+
103
+ # Polynomial coefficients representing one.
104
+ polyone = np.array([1])
105
+
106
+ # Polynomial coefficients representing the identity x.
107
+ polyx = np.array([0, 1])
108
+
109
+ #
110
+ # Polynomial series functions
111
+ #
112
+
113
+
114
+ def polyline(off, scl):
115
+ """
116
+ Returns an array representing a linear polynomial.
117
+
118
+ Parameters
119
+ ----------
120
+ off, scl : scalars
121
+ The "y-intercept" and "slope" of the line, respectively.
122
+
123
+ Returns
124
+ -------
125
+ y : ndarray
126
+ This module's representation of the linear polynomial ``off +
127
+ scl*x``.
128
+
129
+ See Also
130
+ --------
131
+ numpy.polynomial.chebyshev.chebline
132
+ numpy.polynomial.legendre.legline
133
+ numpy.polynomial.laguerre.lagline
134
+ numpy.polynomial.hermite.hermline
135
+ numpy.polynomial.hermite_e.hermeline
136
+
137
+ Examples
138
+ --------
139
+ >>> from numpy.polynomial import polynomial as P
140
+ >>> P.polyline(1, -1)
141
+ array([ 1, -1])
142
+ >>> P.polyval(1, P.polyline(1, -1)) # should be 0
143
+ 0.0
144
+
145
+ """
146
+ if scl != 0:
147
+ return np.array([off, scl])
148
+ else:
149
+ return np.array([off])
150
+
151
+
152
+ def polyfromroots(roots):
153
+ """
154
+ Generate a monic polynomial with given roots.
155
+
156
+ Return the coefficients of the polynomial
157
+
158
+ .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
159
+
160
+ where the :math:`r_n` are the roots specified in `roots`. If a zero has
161
+ multiplicity n, then it must appear in `roots` n times. For instance,
162
+ if 2 is a root of multiplicity three and 3 is a root of multiplicity 2,
163
+ then `roots` looks something like [2, 2, 2, 3, 3]. The roots can appear
164
+ in any order.
165
+
166
+ If the returned coefficients are `c`, then
167
+
168
+ .. math:: p(x) = c_0 + c_1 * x + ... + x^n
169
+
170
+ The coefficient of the last term is 1 for monic polynomials in this
171
+ form.
172
+
173
+ Parameters
174
+ ----------
175
+ roots : array_like
176
+ Sequence containing the roots.
177
+
178
+ Returns
179
+ -------
180
+ out : ndarray
181
+ 1-D array of the polynomial's coefficients If all the roots are
182
+ real, then `out` is also real, otherwise it is complex. (see
183
+ Examples below).
184
+
185
+ See Also
186
+ --------
187
+ numpy.polynomial.chebyshev.chebfromroots
188
+ numpy.polynomial.legendre.legfromroots
189
+ numpy.polynomial.laguerre.lagfromroots
190
+ numpy.polynomial.hermite.hermfromroots
191
+ numpy.polynomial.hermite_e.hermefromroots
192
+
193
+ Notes
194
+ -----
195
+ The coefficients are determined by multiplying together linear factors
196
+ of the form ``(x - r_i)``, i.e.
197
+
198
+ .. math:: p(x) = (x - r_0) (x - r_1) ... (x - r_n)
199
+
200
+ where ``n == len(roots) - 1``; note that this implies that ``1`` is always
201
+ returned for :math:`a_n`.
202
+
203
+ Examples
204
+ --------
205
+ >>> from numpy.polynomial import polynomial as P
206
+ >>> P.polyfromroots((-1,0,1)) # x(x - 1)(x + 1) = x^3 - x
207
+ array([ 0., -1., 0., 1.])
208
+ >>> j = complex(0,1)
209
+ >>> P.polyfromroots((-j,j)) # complex returned, though values are real
210
+ array([1.+0.j, 0.+0.j, 1.+0.j])
211
+
212
+ """
213
+ return pu._fromroots(polyline, polymul, roots)
214
+
215
+
216
+ def polyadd(c1, c2):
217
+ """
218
+ Add one polynomial to another.
219
+
220
+ Returns the sum of two polynomials `c1` + `c2`. The arguments are
221
+ sequences of coefficients from lowest order term to highest, i.e.,
222
+ [1,2,3] represents the polynomial ``1 + 2*x + 3*x**2``.
223
+
224
+ Parameters
225
+ ----------
226
+ c1, c2 : array_like
227
+ 1-D arrays of polynomial coefficients ordered from low to high.
228
+
229
+ Returns
230
+ -------
231
+ out : ndarray
232
+ The coefficient array representing their sum.
233
+
234
+ See Also
235
+ --------
236
+ polysub, polymulx, polymul, polydiv, polypow
237
+
238
+ Examples
239
+ --------
240
+ >>> from numpy.polynomial import polynomial as P
241
+ >>> c1 = (1, 2, 3)
242
+ >>> c2 = (3, 2, 1)
243
+ >>> sum = P.polyadd(c1,c2); sum
244
+ array([4., 4., 4.])
245
+ >>> P.polyval(2, sum) # 4 + 4(2) + 4(2**2)
246
+ 28.0
247
+
248
+ """
249
+ return pu._add(c1, c2)
250
+
251
+
252
+ def polysub(c1, c2):
253
+ """
254
+ Subtract one polynomial from another.
255
+
256
+ Returns the difference of two polynomials `c1` - `c2`. The arguments
257
+ are sequences of coefficients from lowest order term to highest, i.e.,
258
+ [1,2,3] represents the polynomial ``1 + 2*x + 3*x**2``.
259
+
260
+ Parameters
261
+ ----------
262
+ c1, c2 : array_like
263
+ 1-D arrays of polynomial coefficients ordered from low to
264
+ high.
265
+
266
+ Returns
267
+ -------
268
+ out : ndarray
269
+ Of coefficients representing their difference.
270
+
271
+ See Also
272
+ --------
273
+ polyadd, polymulx, polymul, polydiv, polypow
274
+
275
+ Examples
276
+ --------
277
+ >>> from numpy.polynomial import polynomial as P
278
+ >>> c1 = (1, 2, 3)
279
+ >>> c2 = (3, 2, 1)
280
+ >>> P.polysub(c1,c2)
281
+ array([-2., 0., 2.])
282
+ >>> P.polysub(c2, c1) # -P.polysub(c1,c2)
283
+ array([ 2., 0., -2.])
284
+
285
+ """
286
+ return pu._sub(c1, c2)
287
+
288
+
289
+ def polymulx(c):
290
+ """Multiply a polynomial by x.
291
+
292
+ Multiply the polynomial `c` by x, where x is the independent
293
+ variable.
294
+
295
+
296
+ Parameters
297
+ ----------
298
+ c : array_like
299
+ 1-D array of polynomial coefficients ordered from low to
300
+ high.
301
+
302
+ Returns
303
+ -------
304
+ out : ndarray
305
+ Array representing the result of the multiplication.
306
+
307
+ See Also
308
+ --------
309
+ polyadd, polysub, polymul, polydiv, polypow
310
+
311
+ Examples
312
+ --------
313
+ >>> from numpy.polynomial import polynomial as P
314
+ >>> c = (1, 2, 3)
315
+ >>> P.polymulx(c)
316
+ array([0., 1., 2., 3.])
317
+
318
+ """
319
+ # c is a trimmed copy
320
+ [c] = pu.as_series([c])
321
+ # The zero series needs special treatment
322
+ if len(c) == 1 and c[0] == 0:
323
+ return c
324
+
325
+ prd = np.empty(len(c) + 1, dtype=c.dtype)
326
+ prd[0] = c[0] * 0
327
+ prd[1:] = c
328
+ return prd
329
+
330
+
331
+ def polymul(c1, c2):
332
+ """
333
+ Multiply one polynomial by another.
334
+
335
+ Returns the product of two polynomials `c1` * `c2`. The arguments are
336
+ sequences of coefficients, from lowest order term to highest, e.g.,
337
+ [1,2,3] represents the polynomial ``1 + 2*x + 3*x**2.``
338
+
339
+ Parameters
340
+ ----------
341
+ c1, c2 : array_like
342
+ 1-D arrays of coefficients representing a polynomial, relative to the
343
+ "standard" basis, and ordered from lowest order term to highest.
344
+
345
+ Returns
346
+ -------
347
+ out : ndarray
348
+ Of the coefficients of their product.
349
+
350
+ See Also
351
+ --------
352
+ polyadd, polysub, polymulx, polydiv, polypow
353
+
354
+ Examples
355
+ --------
356
+ >>> from numpy.polynomial import polynomial as P
357
+ >>> c1 = (1, 2, 3)
358
+ >>> c2 = (3, 2, 1)
359
+ >>> P.polymul(c1, c2)
360
+ array([ 3., 8., 14., 8., 3.])
361
+
362
+ """
363
+ # c1, c2 are trimmed copies
364
+ [c1, c2] = pu.as_series([c1, c2])
365
+ ret = np.convolve(c1, c2)
366
+ return pu.trimseq(ret)
367
+
368
+
369
+ def polydiv(c1, c2):
370
+ """
371
+ Divide one polynomial by another.
372
+
373
+ Returns the quotient-with-remainder of two polynomials `c1` / `c2`.
374
+ The arguments are sequences of coefficients, from lowest order term
375
+ to highest, e.g., [1,2,3] represents ``1 + 2*x + 3*x**2``.
376
+
377
+ Parameters
378
+ ----------
379
+ c1, c2 : array_like
380
+ 1-D arrays of polynomial coefficients ordered from low to high.
381
+
382
+ Returns
383
+ -------
384
+ [quo, rem] : ndarrays
385
+ Of coefficient series representing the quotient and remainder.
386
+
387
+ See Also
388
+ --------
389
+ polyadd, polysub, polymulx, polymul, polypow
390
+
391
+ Examples
392
+ --------
393
+ >>> from numpy.polynomial import polynomial as P
394
+ >>> c1 = (1, 2, 3)
395
+ >>> c2 = (3, 2, 1)
396
+ >>> P.polydiv(c1, c2)
397
+ (array([3.]), array([-8., -4.]))
398
+ >>> P.polydiv(c2, c1)
399
+ (array([ 0.33333333]), array([ 2.66666667, 1.33333333])) # may vary
400
+
401
+ """
402
+ # c1, c2 are trimmed copies
403
+ [c1, c2] = pu.as_series([c1, c2])
404
+ if c2[-1] == 0:
405
+ raise ZeroDivisionError # FIXME: add message with details to exception
406
+
407
+ # note: this is more efficient than `pu._div(polymul, c1, c2)`
408
+ lc1 = len(c1)
409
+ lc2 = len(c2)
410
+ if lc1 < lc2:
411
+ return c1[:1] * 0, c1
412
+ elif lc2 == 1:
413
+ return c1 / c2[-1], c1[:1] * 0
414
+ else:
415
+ dlen = lc1 - lc2
416
+ scl = c2[-1]
417
+ c2 = c2[:-1] / scl
418
+ i = dlen
419
+ j = lc1 - 1
420
+ while i >= 0:
421
+ c1[i:j] -= c2 * c1[j]
422
+ i -= 1
423
+ j -= 1
424
+ return c1[j + 1:] / scl, pu.trimseq(c1[:j + 1])
425
+
426
+
427
+ def polypow(c, pow, maxpower=None):
428
+ """Raise a polynomial to a power.
429
+
430
+ Returns the polynomial `c` raised to the power `pow`. The argument
431
+ `c` is a sequence of coefficients ordered from low to high. i.e.,
432
+ [1,2,3] is the series ``1 + 2*x + 3*x**2.``
433
+
434
+ Parameters
435
+ ----------
436
+ c : array_like
437
+ 1-D array of array of series coefficients ordered from low to
438
+ high degree.
439
+ pow : integer
440
+ Power to which the series will be raised
441
+ maxpower : integer, optional
442
+ Maximum power allowed. This is mainly to limit growth of the series
443
+ to unmanageable size. Default is 16
444
+
445
+ Returns
446
+ -------
447
+ coef : ndarray
448
+ Power series of power.
449
+
450
+ See Also
451
+ --------
452
+ polyadd, polysub, polymulx, polymul, polydiv
453
+
454
+ Examples
455
+ --------
456
+ >>> from numpy.polynomial import polynomial as P
457
+ >>> P.polypow([1, 2, 3], 2)
458
+ array([ 1., 4., 10., 12., 9.])
459
+
460
+ """
461
+ # note: this is more efficient than `pu._pow(polymul, c1, c2)`, as it
462
+ # avoids calling `as_series` repeatedly
463
+ return pu._pow(np.convolve, c, pow, maxpower)
464
+
465
+
466
+ def polyder(c, m=1, scl=1, axis=0):
467
+ """
468
+ Differentiate a polynomial.
469
+
470
+ Returns the polynomial coefficients `c` differentiated `m` times along
471
+ `axis`. At each iteration the result is multiplied by `scl` (the
472
+ scaling factor is for use in a linear change of variable). The
473
+ argument `c` is an array of coefficients from low to high degree along
474
+ each axis, e.g., [1,2,3] represents the polynomial ``1 + 2*x + 3*x**2``
475
+ while [[1,2],[1,2]] represents ``1 + 1*x + 2*y + 2*x*y`` if axis=0 is
476
+ ``x`` and axis=1 is ``y``.
477
+
478
+ Parameters
479
+ ----------
480
+ c : array_like
481
+ Array of polynomial coefficients. If c is multidimensional the
482
+ different axis correspond to different variables with the degree
483
+ in each axis given by the corresponding index.
484
+ m : int, optional
485
+ Number of derivatives taken, must be non-negative. (Default: 1)
486
+ scl : scalar, optional
487
+ Each differentiation is multiplied by `scl`. The end result is
488
+ multiplication by ``scl**m``. This is for use in a linear change
489
+ of variable. (Default: 1)
490
+ axis : int, optional
491
+ Axis over which the derivative is taken. (Default: 0).
492
+
493
+ Returns
494
+ -------
495
+ der : ndarray
496
+ Polynomial coefficients of the derivative.
497
+
498
+ See Also
499
+ --------
500
+ polyint
501
+
502
+ Examples
503
+ --------
504
+ >>> from numpy.polynomial import polynomial as P
505
+ >>> c = (1, 2, 3, 4)
506
+ >>> P.polyder(c) # (d/dx)(c)
507
+ array([ 2., 6., 12.])
508
+ >>> P.polyder(c, 3) # (d**3/dx**3)(c)
509
+ array([24.])
510
+ >>> P.polyder(c, scl=-1) # (d/d(-x))(c)
511
+ array([ -2., -6., -12.])
512
+ >>> P.polyder(c, 2, -1) # (d**2/d(-x)**2)(c)
513
+ array([ 6., 24.])
514
+
515
+ """
516
+ c = np.array(c, ndmin=1, copy=True)
517
+ if c.dtype.char in '?bBhHiIlLqQpP':
518
+ # astype fails with NA
519
+ c = c + 0.0
520
+ cdt = c.dtype
521
+ cnt = pu._as_int(m, "the order of derivation")
522
+ iaxis = pu._as_int(axis, "the axis")
523
+ if cnt < 0:
524
+ raise ValueError("The order of derivation must be non-negative")
525
+ iaxis = normalize_axis_index(iaxis, c.ndim)
526
+
527
+ if cnt == 0:
528
+ return c
529
+
530
+ c = np.moveaxis(c, iaxis, 0)
531
+ n = len(c)
532
+ if cnt >= n:
533
+ c = c[:1] * 0
534
+ else:
535
+ for i in range(cnt):
536
+ n = n - 1
537
+ c *= scl
538
+ der = np.empty((n,) + c.shape[1:], dtype=cdt)
539
+ for j in range(n, 0, -1):
540
+ der[j - 1] = j * c[j]
541
+ c = der
542
+ c = np.moveaxis(c, 0, iaxis)
543
+ return c
544
+
545
+
546
+ def polyint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
547
+ """
548
+ Integrate a polynomial.
549
+
550
+ Returns the polynomial coefficients `c` integrated `m` times from
551
+ `lbnd` along `axis`. At each iteration the resulting series is
552
+ **multiplied** by `scl` and an integration constant, `k`, is added.
553
+ The scaling factor is for use in a linear change of variable. ("Buyer
554
+ beware": note that, depending on what one is doing, one may want `scl`
555
+ to be the reciprocal of what one might expect; for more information,
556
+ see the Notes section below.) The argument `c` is an array of
557
+ coefficients, from low to high degree along each axis, e.g., [1,2,3]
558
+ represents the polynomial ``1 + 2*x + 3*x**2`` while [[1,2],[1,2]]
559
+ represents ``1 + 1*x + 2*y + 2*x*y`` if axis=0 is ``x`` and axis=1 is
560
+ ``y``.
561
+
562
+ Parameters
563
+ ----------
564
+ c : array_like
565
+ 1-D array of polynomial coefficients, ordered from low to high.
566
+ m : int, optional
567
+ Order of integration, must be positive. (Default: 1)
568
+ k : {[], list, scalar}, optional
569
+ Integration constant(s). The value of the first integral at zero
570
+ is the first value in the list, the value of the second integral
571
+ at zero is the second value, etc. If ``k == []`` (the default),
572
+ all constants are set to zero. If ``m == 1``, a single scalar can
573
+ be given instead of a list.
574
+ lbnd : scalar, optional
575
+ The lower bound of the integral. (Default: 0)
576
+ scl : scalar, optional
577
+ Following each integration the result is *multiplied* by `scl`
578
+ before the integration constant is added. (Default: 1)
579
+ axis : int, optional
580
+ Axis over which the integral is taken. (Default: 0).
581
+
582
+ Returns
583
+ -------
584
+ S : ndarray
585
+ Coefficient array of the integral.
586
+
587
+ Raises
588
+ ------
589
+ ValueError
590
+ If ``m < 1``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
591
+ ``np.ndim(scl) != 0``.
592
+
593
+ See Also
594
+ --------
595
+ polyder
596
+
597
+ Notes
598
+ -----
599
+ Note that the result of each integration is *multiplied* by `scl`. Why
600
+ is this important to note? Say one is making a linear change of
601
+ variable :math:`u = ax + b` in an integral relative to `x`. Then
602
+ :math:`dx = du/a`, so one will need to set `scl` equal to
603
+ :math:`1/a` - perhaps not what one would have first thought.
604
+
605
+ Examples
606
+ --------
607
+ >>> from numpy.polynomial import polynomial as P
608
+ >>> c = (1, 2, 3)
609
+ >>> P.polyint(c) # should return array([0, 1, 1, 1])
610
+ array([0., 1., 1., 1.])
611
+ >>> P.polyint(c, 3) # should return array([0, 0, 0, 1/6, 1/12, 1/20])
612
+ array([ 0. , 0. , 0. , 0.16666667, 0.08333333, # may vary
613
+ 0.05 ])
614
+ >>> P.polyint(c, k=3) # should return array([3, 1, 1, 1])
615
+ array([3., 1., 1., 1.])
616
+ >>> P.polyint(c,lbnd=-2) # should return array([6, 1, 1, 1])
617
+ array([6., 1., 1., 1.])
618
+ >>> P.polyint(c,scl=-2) # should return array([0, -2, -2, -2])
619
+ array([ 0., -2., -2., -2.])
620
+
621
+ """
622
+ c = np.array(c, ndmin=1, copy=True)
623
+ if c.dtype.char in '?bBhHiIlLqQpP':
624
+ # astype doesn't preserve mask attribute.
625
+ c = c + 0.0
626
+ cdt = c.dtype
627
+ if not np.iterable(k):
628
+ k = [k]
629
+ cnt = pu._as_int(m, "the order of integration")
630
+ iaxis = pu._as_int(axis, "the axis")
631
+ if cnt < 0:
632
+ raise ValueError("The order of integration must be non-negative")
633
+ if len(k) > cnt:
634
+ raise ValueError("Too many integration constants")
635
+ if np.ndim(lbnd) != 0:
636
+ raise ValueError("lbnd must be a scalar.")
637
+ if np.ndim(scl) != 0:
638
+ raise ValueError("scl must be a scalar.")
639
+ iaxis = normalize_axis_index(iaxis, c.ndim)
640
+
641
+ if cnt == 0:
642
+ return c
643
+
644
+ k = list(k) + [0] * (cnt - len(k))
645
+ c = np.moveaxis(c, iaxis, 0)
646
+ for i in range(cnt):
647
+ n = len(c)
648
+ c *= scl
649
+ if n == 1 and np.all(c[0] == 0):
650
+ c[0] += k[i]
651
+ else:
652
+ tmp = np.empty((n + 1,) + c.shape[1:], dtype=cdt)
653
+ tmp[0] = c[0] * 0
654
+ tmp[1] = c[0]
655
+ for j in range(1, n):
656
+ tmp[j + 1] = c[j] / (j + 1)
657
+ tmp[0] += k[i] - polyval(lbnd, tmp)
658
+ c = tmp
659
+ c = np.moveaxis(c, 0, iaxis)
660
+ return c
661
+
662
+
663
+ def polyval(x, c, tensor=True):
664
+ """
665
+ Evaluate a polynomial at points x.
666
+
667
+ If `c` is of length ``n + 1``, this function returns the value
668
+
669
+ .. math:: p(x) = c_0 + c_1 * x + ... + c_n * x^n
670
+
671
+ The parameter `x` is converted to an array only if it is a tuple or a
672
+ list, otherwise it is treated as a scalar. In either case, either `x`
673
+ or its elements must support multiplication and addition both with
674
+ themselves and with the elements of `c`.
675
+
676
+ If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If
677
+ `c` is multidimensional, then the shape of the result depends on the
678
+ value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
679
+ x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
680
+ scalars have shape (,).
681
+
682
+ Trailing zeros in the coefficients will be used in the evaluation, so
683
+ they should be avoided if efficiency is a concern.
684
+
685
+ Parameters
686
+ ----------
687
+ x : array_like, compatible object
688
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
689
+ it is left unchanged and treated as a scalar. In either case, `x`
690
+ or its elements must support addition and multiplication with
691
+ with themselves and with the elements of `c`.
692
+ c : array_like
693
+ Array of coefficients ordered so that the coefficients for terms of
694
+ degree n are contained in c[n]. If `c` is multidimensional the
695
+ remaining indices enumerate multiple polynomials. In the two
696
+ dimensional case the coefficients may be thought of as stored in
697
+ the columns of `c`.
698
+ tensor : boolean, optional
699
+ If True, the shape of the coefficient array is extended with ones
700
+ on the right, one for each dimension of `x`. Scalars have dimension 0
701
+ for this action. The result is that every column of coefficients in
702
+ `c` is evaluated for every element of `x`. If False, `x` is broadcast
703
+ over the columns of `c` for the evaluation. This keyword is useful
704
+ when `c` is multidimensional. The default value is True.
705
+
706
+ Returns
707
+ -------
708
+ values : ndarray, compatible object
709
+ The shape of the returned array is described above.
710
+
711
+ See Also
712
+ --------
713
+ polyval2d, polygrid2d, polyval3d, polygrid3d
714
+
715
+ Notes
716
+ -----
717
+ The evaluation uses Horner's method.
718
+
719
+ Examples
720
+ --------
721
+ >>> import numpy as np
722
+ >>> from numpy.polynomial.polynomial import polyval
723
+ >>> polyval(1, [1,2,3])
724
+ 6.0
725
+ >>> a = np.arange(4).reshape(2,2)
726
+ >>> a
727
+ array([[0, 1],
728
+ [2, 3]])
729
+ >>> polyval(a, [1, 2, 3])
730
+ array([[ 1., 6.],
731
+ [17., 34.]])
732
+ >>> coef = np.arange(4).reshape(2, 2) # multidimensional coefficients
733
+ >>> coef
734
+ array([[0, 1],
735
+ [2, 3]])
736
+ >>> polyval([1, 2], coef, tensor=True)
737
+ array([[2., 4.],
738
+ [4., 7.]])
739
+ >>> polyval([1, 2], coef, tensor=False)
740
+ array([2., 7.])
741
+
742
+ """
743
+ c = np.array(c, ndmin=1, copy=None)
744
+ if c.dtype.char in '?bBhHiIlLqQpP':
745
+ # astype fails with NA
746
+ c = c + 0.0
747
+ if isinstance(x, (tuple, list)):
748
+ x = np.asarray(x)
749
+ if isinstance(x, np.ndarray) and tensor:
750
+ c = c.reshape(c.shape + (1,) * x.ndim)
751
+
752
+ c0 = c[-1] + x * 0
753
+ for i in range(2, len(c) + 1):
754
+ c0 = c[-i] + c0 * x
755
+ return c0
756
+
757
+
758
+ def polyvalfromroots(x, r, tensor=True):
759
+ """
760
+ Evaluate a polynomial specified by its roots at points x.
761
+
762
+ If `r` is of length ``N``, this function returns the value
763
+
764
+ .. math:: p(x) = \\prod_{n=1}^{N} (x - r_n)
765
+
766
+ The parameter `x` is converted to an array only if it is a tuple or a
767
+ list, otherwise it is treated as a scalar. In either case, either `x`
768
+ or its elements must support multiplication and addition both with
769
+ themselves and with the elements of `r`.
770
+
771
+ If `r` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If `r`
772
+ is multidimensional, then the shape of the result depends on the value of
773
+ `tensor`. If `tensor` is ``True`` the shape will be r.shape[1:] + x.shape;
774
+ that is, each polynomial is evaluated at every value of `x`. If `tensor` is
775
+ ``False``, the shape will be r.shape[1:]; that is, each polynomial is
776
+ evaluated only for the corresponding broadcast value of `x`. Note that
777
+ scalars have shape (,).
778
+
779
+ Parameters
780
+ ----------
781
+ x : array_like, compatible object
782
+ If `x` is a list or tuple, it is converted to an ndarray, otherwise
783
+ it is left unchanged and treated as a scalar. In either case, `x`
784
+ or its elements must support addition and multiplication with
785
+ with themselves and with the elements of `r`.
786
+ r : array_like
787
+ Array of roots. If `r` is multidimensional the first index is the
788
+ root index, while the remaining indices enumerate multiple
789
+ polynomials. For instance, in the two dimensional case the roots
790
+ of each polynomial may be thought of as stored in the columns of `r`.
791
+ tensor : boolean, optional
792
+ If True, the shape of the roots array is extended with ones on the
793
+ right, one for each dimension of `x`. Scalars have dimension 0 for this
794
+ action. The result is that every column of coefficients in `r` is
795
+ evaluated for every element of `x`. If False, `x` is broadcast over the
796
+ columns of `r` for the evaluation. This keyword is useful when `r` is
797
+ multidimensional. The default value is True.
798
+
799
+ Returns
800
+ -------
801
+ values : ndarray, compatible object
802
+ The shape of the returned array is described above.
803
+
804
+ See Also
805
+ --------
806
+ polyroots, polyfromroots, polyval
807
+
808
+ Examples
809
+ --------
810
+ >>> from numpy.polynomial.polynomial import polyvalfromroots
811
+ >>> polyvalfromroots(1, [1, 2, 3])
812
+ 0.0
813
+ >>> a = np.arange(4).reshape(2, 2)
814
+ >>> a
815
+ array([[0, 1],
816
+ [2, 3]])
817
+ >>> polyvalfromroots(a, [-1, 0, 1])
818
+ array([[-0., 0.],
819
+ [ 6., 24.]])
820
+ >>> r = np.arange(-2, 2).reshape(2,2) # multidimensional coefficients
821
+ >>> r # each column of r defines one polynomial
822
+ array([[-2, -1],
823
+ [ 0, 1]])
824
+ >>> b = [-2, 1]
825
+ >>> polyvalfromroots(b, r, tensor=True)
826
+ array([[-0., 3.],
827
+ [ 3., 0.]])
828
+ >>> polyvalfromroots(b, r, tensor=False)
829
+ array([-0., 0.])
830
+
831
+ """
832
+ r = np.array(r, ndmin=1, copy=None)
833
+ if r.dtype.char in '?bBhHiIlLqQpP':
834
+ r = r.astype(np.double)
835
+ if isinstance(x, (tuple, list)):
836
+ x = np.asarray(x)
837
+ if isinstance(x, np.ndarray):
838
+ if tensor:
839
+ r = r.reshape(r.shape + (1,) * x.ndim)
840
+ elif x.ndim >= r.ndim:
841
+ raise ValueError("x.ndim must be < r.ndim when tensor == False")
842
+ return np.prod(x - r, axis=0)
843
+
844
+
845
+ def polyval2d(x, y, c):
846
+ """
847
+ Evaluate a 2-D polynomial at points (x, y).
848
+
849
+ This function returns the value
850
+
851
+ .. math:: p(x,y) = \\sum_{i,j} c_{i,j} * x^i * y^j
852
+
853
+ The parameters `x` and `y` are converted to arrays only if they are
854
+ tuples or a lists, otherwise they are treated as a scalars and they
855
+ must have the same shape after conversion. In either case, either `x`
856
+ and `y` or their elements must support multiplication and addition both
857
+ with themselves and with the elements of `c`.
858
+
859
+ If `c` has fewer than two dimensions, ones are implicitly appended to
860
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
861
+ x.shape.
862
+
863
+ Parameters
864
+ ----------
865
+ x, y : array_like, compatible objects
866
+ The two dimensional series is evaluated at the points ``(x, y)``,
867
+ where `x` and `y` must have the same shape. If `x` or `y` is a list
868
+ or tuple, it is first converted to an ndarray, otherwise it is left
869
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
870
+ c : array_like
871
+ Array of coefficients ordered so that the coefficient of the term
872
+ of multi-degree i,j is contained in ``c[i,j]``. If `c` has
873
+ dimension greater than two the remaining indices enumerate multiple
874
+ sets of coefficients.
875
+
876
+ Returns
877
+ -------
878
+ values : ndarray, compatible object
879
+ The values of the two dimensional polynomial at points formed with
880
+ pairs of corresponding values from `x` and `y`.
881
+
882
+ See Also
883
+ --------
884
+ polyval, polygrid2d, polyval3d, polygrid3d
885
+
886
+ Examples
887
+ --------
888
+ >>> from numpy.polynomial import polynomial as P
889
+ >>> c = ((1, 2, 3), (4, 5, 6))
890
+ >>> P.polyval2d(1, 1, c)
891
+ 21.0
892
+
893
+ """
894
+ return pu._valnd(polyval, c, x, y)
895
+
896
+
897
+ def polygrid2d(x, y, c):
898
+ """
899
+ Evaluate a 2-D polynomial on the Cartesian product of x and y.
900
+
901
+ This function returns the values:
902
+
903
+ .. math:: p(a,b) = \\sum_{i,j} c_{i,j} * a^i * b^j
904
+
905
+ where the points ``(a, b)`` consist of all pairs formed by taking
906
+ `a` from `x` and `b` from `y`. The resulting points form a grid with
907
+ `x` in the first dimension and `y` in the second.
908
+
909
+ The parameters `x` and `y` are converted to arrays only if they are
910
+ tuples or a lists, otherwise they are treated as a scalars. In either
911
+ case, either `x` and `y` or their elements must support multiplication
912
+ and addition both with themselves and with the elements of `c`.
913
+
914
+ If `c` has fewer than two dimensions, ones are implicitly appended to
915
+ its shape to make it 2-D. The shape of the result will be c.shape[2:] +
916
+ x.shape + y.shape.
917
+
918
+ Parameters
919
+ ----------
920
+ x, y : array_like, compatible objects
921
+ The two dimensional series is evaluated at the points in the
922
+ Cartesian product of `x` and `y`. If `x` or `y` is a list or
923
+ tuple, it is first converted to an ndarray, otherwise it is left
924
+ unchanged and, if it isn't an ndarray, it is treated as a scalar.
925
+ c : array_like
926
+ Array of coefficients ordered so that the coefficients for terms of
927
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
928
+ greater than two the remaining indices enumerate multiple sets of
929
+ coefficients.
930
+
931
+ Returns
932
+ -------
933
+ values : ndarray, compatible object
934
+ The values of the two dimensional polynomial at points in the Cartesian
935
+ product of `x` and `y`.
936
+
937
+ See Also
938
+ --------
939
+ polyval, polyval2d, polyval3d, polygrid3d
940
+
941
+ Examples
942
+ --------
943
+ >>> from numpy.polynomial import polynomial as P
944
+ >>> c = ((1, 2, 3), (4, 5, 6))
945
+ >>> P.polygrid2d([0, 1], [0, 1], c)
946
+ array([[ 1., 6.],
947
+ [ 5., 21.]])
948
+
949
+ """
950
+ return pu._gridnd(polyval, c, x, y)
951
+
952
+
953
+ def polyval3d(x, y, z, c):
954
+ """
955
+ Evaluate a 3-D polynomial at points (x, y, z).
956
+
957
+ This function returns the values:
958
+
959
+ .. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * x^i * y^j * z^k
960
+
961
+ The parameters `x`, `y`, and `z` are converted to arrays only if
962
+ they are tuples or a lists, otherwise they are treated as a scalars and
963
+ they must have the same shape after conversion. In either case, either
964
+ `x`, `y`, and `z` or their elements must support multiplication and
965
+ addition both with themselves and with the elements of `c`.
966
+
967
+ If `c` has fewer than 3 dimensions, ones are implicitly appended to its
968
+ shape to make it 3-D. The shape of the result will be c.shape[3:] +
969
+ x.shape.
970
+
971
+ Parameters
972
+ ----------
973
+ x, y, z : array_like, compatible object
974
+ The three dimensional series is evaluated at the points
975
+ ``(x, y, z)``, where `x`, `y`, and `z` must have the same shape. If
976
+ any of `x`, `y`, or `z` is a list or tuple, it is first converted
977
+ to an ndarray, otherwise it is left unchanged and if it isn't an
978
+ ndarray it is treated as a scalar.
979
+ c : array_like
980
+ Array of coefficients ordered so that the coefficient of the term of
981
+ multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
982
+ greater than 3 the remaining indices enumerate multiple sets of
983
+ coefficients.
984
+
985
+ Returns
986
+ -------
987
+ values : ndarray, compatible object
988
+ The values of the multidimensional polynomial on points formed with
989
+ triples of corresponding values from `x`, `y`, and `z`.
990
+
991
+ See Also
992
+ --------
993
+ polyval, polyval2d, polygrid2d, polygrid3d
994
+
995
+ Examples
996
+ --------
997
+ >>> from numpy.polynomial import polynomial as P
998
+ >>> c = ((1, 2, 3), (4, 5, 6), (7, 8, 9))
999
+ >>> P.polyval3d(1, 1, 1, c)
1000
+ 45.0
1001
+
1002
+ """
1003
+ return pu._valnd(polyval, c, x, y, z)
1004
+
1005
+
1006
+ def polygrid3d(x, y, z, c):
1007
+ """
1008
+ Evaluate a 3-D polynomial on the Cartesian product of x, y and z.
1009
+
1010
+ This function returns the values:
1011
+
1012
+ .. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * a^i * b^j * c^k
1013
+
1014
+ where the points ``(a, b, c)`` consist of all triples formed by taking
1015
+ `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
1016
+ a grid with `x` in the first dimension, `y` in the second, and `z` in
1017
+ the third.
1018
+
1019
+ The parameters `x`, `y`, and `z` are converted to arrays only if they
1020
+ are tuples or a lists, otherwise they are treated as a scalars. In
1021
+ either case, either `x`, `y`, and `z` or their elements must support
1022
+ multiplication and addition both with themselves and with the elements
1023
+ of `c`.
1024
+
1025
+ If `c` has fewer than three dimensions, ones are implicitly appended to
1026
+ its shape to make it 3-D. The shape of the result will be c.shape[3:] +
1027
+ x.shape + y.shape + z.shape.
1028
+
1029
+ Parameters
1030
+ ----------
1031
+ x, y, z : array_like, compatible objects
1032
+ The three dimensional series is evaluated at the points in the
1033
+ Cartesian product of `x`, `y`, and `z`. If `x`, `y`, or `z` is a
1034
+ list or tuple, it is first converted to an ndarray, otherwise it is
1035
+ left unchanged and, if it isn't an ndarray, it is treated as a
1036
+ scalar.
1037
+ c : array_like
1038
+ Array of coefficients ordered so that the coefficients for terms of
1039
+ degree i,j are contained in ``c[i,j]``. If `c` has dimension
1040
+ greater than two the remaining indices enumerate multiple sets of
1041
+ coefficients.
1042
+
1043
+ Returns
1044
+ -------
1045
+ values : ndarray, compatible object
1046
+ The values of the two dimensional polynomial at points in the Cartesian
1047
+ product of `x` and `y`.
1048
+
1049
+ See Also
1050
+ --------
1051
+ polyval, polyval2d, polygrid2d, polyval3d
1052
+
1053
+ Examples
1054
+ --------
1055
+ >>> from numpy.polynomial import polynomial as P
1056
+ >>> c = ((1, 2, 3), (4, 5, 6), (7, 8, 9))
1057
+ >>> P.polygrid3d([0, 1], [0, 1], [0, 1], c)
1058
+ array([[ 1., 13.],
1059
+ [ 6., 51.]])
1060
+
1061
+ """
1062
+ return pu._gridnd(polyval, c, x, y, z)
1063
+
1064
+
1065
+ def polyvander(x, deg):
1066
+ """Vandermonde matrix of given degree.
1067
+
1068
+ Returns the Vandermonde matrix of degree `deg` and sample points
1069
+ `x`. The Vandermonde matrix is defined by
1070
+
1071
+ .. math:: V[..., i] = x^i,
1072
+
1073
+ where ``0 <= i <= deg``. The leading indices of `V` index the elements of
1074
+ `x` and the last index is the power of `x`.
1075
+
1076
+ If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
1077
+ matrix ``V = polyvander(x, n)``, then ``np.dot(V, c)`` and
1078
+ ``polyval(x, c)`` are the same up to roundoff. This equivalence is
1079
+ useful both for least squares fitting and for the evaluation of a large
1080
+ number of polynomials of the same degree and sample points.
1081
+
1082
+ Parameters
1083
+ ----------
1084
+ x : array_like
1085
+ Array of points. The dtype is converted to float64 or complex128
1086
+ depending on whether any of the elements are complex. If `x` is
1087
+ scalar it is converted to a 1-D array.
1088
+ deg : int
1089
+ Degree of the resulting matrix.
1090
+
1091
+ Returns
1092
+ -------
1093
+ vander : ndarray.
1094
+ The Vandermonde matrix. The shape of the returned matrix is
1095
+ ``x.shape + (deg + 1,)``, where the last index is the power of `x`.
1096
+ The dtype will be the same as the converted `x`.
1097
+
1098
+ See Also
1099
+ --------
1100
+ polyvander2d, polyvander3d
1101
+
1102
+ Examples
1103
+ --------
1104
+ The Vandermonde matrix of degree ``deg = 5`` and sample points
1105
+ ``x = [-1, 2, 3]`` contains the element-wise powers of `x`
1106
+ from 0 to 5 as its columns.
1107
+
1108
+ >>> from numpy.polynomial import polynomial as P
1109
+ >>> x, deg = [-1, 2, 3], 5
1110
+ >>> P.polyvander(x=x, deg=deg)
1111
+ array([[ 1., -1., 1., -1., 1., -1.],
1112
+ [ 1., 2., 4., 8., 16., 32.],
1113
+ [ 1., 3., 9., 27., 81., 243.]])
1114
+
1115
+ """
1116
+ ideg = pu._as_int(deg, "deg")
1117
+ if ideg < 0:
1118
+ raise ValueError("deg must be non-negative")
1119
+
1120
+ x = np.array(x, copy=None, ndmin=1) + 0.0
1121
+ dims = (ideg + 1,) + x.shape
1122
+ dtyp = x.dtype
1123
+ v = np.empty(dims, dtype=dtyp)
1124
+ v[0] = x * 0 + 1
1125
+ if ideg > 0:
1126
+ v[1] = x
1127
+ for i in range(2, ideg + 1):
1128
+ v[i] = v[i - 1] * x
1129
+ return np.moveaxis(v, 0, -1)
1130
+
1131
+
1132
+ def polyvander2d(x, y, deg):
1133
+ """Pseudo-Vandermonde matrix of given degrees.
1134
+
1135
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1136
+ points ``(x, y)``. The pseudo-Vandermonde matrix is defined by
1137
+
1138
+ .. math:: V[..., (deg[1] + 1)*i + j] = x^i * y^j,
1139
+
1140
+ where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of
1141
+ `V` index the points ``(x, y)`` and the last index encodes the powers of
1142
+ `x` and `y`.
1143
+
1144
+ If ``V = polyvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
1145
+ correspond to the elements of a 2-D coefficient array `c` of shape
1146
+ (xdeg + 1, ydeg + 1) in the order
1147
+
1148
+ .. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...
1149
+
1150
+ and ``np.dot(V, c.flat)`` and ``polyval2d(x, y, c)`` will be the same
1151
+ up to roundoff. This equivalence is useful both for least squares
1152
+ fitting and for the evaluation of a large number of 2-D polynomials
1153
+ of the same degrees and sample points.
1154
+
1155
+ Parameters
1156
+ ----------
1157
+ x, y : array_like
1158
+ Arrays of point coordinates, all of the same shape. The dtypes
1159
+ will be converted to either float64 or complex128 depending on
1160
+ whether any of the elements are complex. Scalars are converted to
1161
+ 1-D arrays.
1162
+ deg : list of ints
1163
+ List of maximum degrees of the form [x_deg, y_deg].
1164
+
1165
+ Returns
1166
+ -------
1167
+ vander2d : ndarray
1168
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1169
+ :math:`order = (deg[0]+1)*(deg([1]+1)`. The dtype will be the same
1170
+ as the converted `x` and `y`.
1171
+
1172
+ See Also
1173
+ --------
1174
+ polyvander, polyvander3d, polyval2d, polyval3d
1175
+
1176
+ Examples
1177
+ --------
1178
+ >>> import numpy as np
1179
+
1180
+ The 2-D pseudo-Vandermonde matrix of degree ``[1, 2]`` and sample
1181
+ points ``x = [-1, 2]`` and ``y = [1, 3]`` is as follows:
1182
+
1183
+ >>> from numpy.polynomial import polynomial as P
1184
+ >>> x = np.array([-1, 2])
1185
+ >>> y = np.array([1, 3])
1186
+ >>> m, n = 1, 2
1187
+ >>> deg = np.array([m, n])
1188
+ >>> V = P.polyvander2d(x=x, y=y, deg=deg)
1189
+ >>> V
1190
+ array([[ 1., 1., 1., -1., -1., -1.],
1191
+ [ 1., 3., 9., 2., 6., 18.]])
1192
+
1193
+ We can verify the columns for any ``0 <= i <= m`` and ``0 <= j <= n``:
1194
+
1195
+ >>> i, j = 0, 1
1196
+ >>> V[:, (deg[1]+1)*i + j] == x**i * y**j
1197
+ array([ True, True])
1198
+
1199
+ The (1D) Vandermonde matrix of sample points ``x`` and degree ``m`` is a
1200
+ special case of the (2D) pseudo-Vandermonde matrix with ``y`` points all
1201
+ zero and degree ``[m, 0]``.
1202
+
1203
+ >>> P.polyvander2d(x=x, y=0*x, deg=(m, 0)) == P.polyvander(x=x, deg=m)
1204
+ array([[ True, True],
1205
+ [ True, True]])
1206
+
1207
+ """
1208
+ return pu._vander_nd_flat((polyvander, polyvander), (x, y), deg)
1209
+
1210
+
1211
+ def polyvander3d(x, y, z, deg):
1212
+ """Pseudo-Vandermonde matrix of given degrees.
1213
+
1214
+ Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1215
+ points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,
1216
+ then The pseudo-Vandermonde matrix is defined by
1217
+
1218
+ .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = x^i * y^j * z^k,
1219
+
1220
+ where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``. The leading
1221
+ indices of `V` index the points ``(x, y, z)`` and the last index encodes
1222
+ the powers of `x`, `y`, and `z`.
1223
+
1224
+ If ``V = polyvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
1225
+ of `V` correspond to the elements of a 3-D coefficient array `c` of
1226
+ shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
1227
+
1228
+ .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
1229
+
1230
+ and ``np.dot(V, c.flat)`` and ``polyval3d(x, y, z, c)`` will be the
1231
+ same up to roundoff. This equivalence is useful both for least squares
1232
+ fitting and for the evaluation of a large number of 3-D polynomials
1233
+ of the same degrees and sample points.
1234
+
1235
+ Parameters
1236
+ ----------
1237
+ x, y, z : array_like
1238
+ Arrays of point coordinates, all of the same shape. The dtypes will
1239
+ be converted to either float64 or complex128 depending on whether
1240
+ any of the elements are complex. Scalars are converted to 1-D
1241
+ arrays.
1242
+ deg : list of ints
1243
+ List of maximum degrees of the form [x_deg, y_deg, z_deg].
1244
+
1245
+ Returns
1246
+ -------
1247
+ vander3d : ndarray
1248
+ The shape of the returned matrix is ``x.shape + (order,)``, where
1249
+ :math:`order = (deg[0]+1)*(deg([1]+1)*(deg[2]+1)`. The dtype will
1250
+ be the same as the converted `x`, `y`, and `z`.
1251
+
1252
+ See Also
1253
+ --------
1254
+ polyvander, polyvander3d, polyval2d, polyval3d
1255
+
1256
+ Examples
1257
+ --------
1258
+ >>> import numpy as np
1259
+ >>> from numpy.polynomial import polynomial as P
1260
+ >>> x = np.asarray([-1, 2, 1])
1261
+ >>> y = np.asarray([1, -2, -3])
1262
+ >>> z = np.asarray([2, 2, 5])
1263
+ >>> l, m, n = [2, 2, 1]
1264
+ >>> deg = [l, m, n]
1265
+ >>> V = P.polyvander3d(x=x, y=y, z=z, deg=deg)
1266
+ >>> V
1267
+ array([[ 1., 2., 1., 2., 1., 2., -1., -2., -1.,
1268
+ -2., -1., -2., 1., 2., 1., 2., 1., 2.],
1269
+ [ 1., 2., -2., -4., 4., 8., 2., 4., -4.,
1270
+ -8., 8., 16., 4., 8., -8., -16., 16., 32.],
1271
+ [ 1., 5., -3., -15., 9., 45., 1., 5., -3.,
1272
+ -15., 9., 45., 1., 5., -3., -15., 9., 45.]])
1273
+
1274
+ We can verify the columns for any ``0 <= i <= l``, ``0 <= j <= m``,
1275
+ and ``0 <= k <= n``
1276
+
1277
+ >>> i, j, k = 2, 1, 0
1278
+ >>> V[:, (m+1)*(n+1)*i + (n+1)*j + k] == x**i * y**j * z**k
1279
+ array([ True, True, True])
1280
+
1281
+ """
1282
+ return pu._vander_nd_flat((polyvander, polyvander, polyvander), (x, y, z), deg)
1283
+
1284
+
1285
+ def polyfit(x, y, deg, rcond=None, full=False, w=None):
1286
+ """
1287
+ Least-squares fit of a polynomial to data.
1288
+
1289
+ Return the coefficients of a polynomial of degree `deg` that is the
1290
+ least squares fit to the data values `y` given at points `x`. If `y` is
1291
+ 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1292
+ fits are done, one for each column of `y`, and the resulting
1293
+ coefficients are stored in the corresponding columns of a 2-D return.
1294
+ The fitted polynomial(s) are in the form
1295
+
1296
+ .. math:: p(x) = c_0 + c_1 * x + ... + c_n * x^n,
1297
+
1298
+ where `n` is `deg`.
1299
+
1300
+ Parameters
1301
+ ----------
1302
+ x : array_like, shape (`M`,)
1303
+ x-coordinates of the `M` sample (data) points ``(x[i], y[i])``.
1304
+ y : array_like, shape (`M`,) or (`M`, `K`)
1305
+ y-coordinates of the sample points. Several sets of sample points
1306
+ sharing the same x-coordinates can be (independently) fit with one
1307
+ call to `polyfit` by passing in for `y` a 2-D array that contains
1308
+ one data set per column.
1309
+ deg : int or 1-D array_like
1310
+ Degree(s) of the fitting polynomials. If `deg` is a single integer
1311
+ all terms up to and including the `deg`'th term are included in the
1312
+ fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1313
+ degrees of the terms to include may be used instead.
1314
+ rcond : float, optional
1315
+ Relative condition number of the fit. Singular values smaller
1316
+ than `rcond`, relative to the largest singular value, will be
1317
+ ignored. The default value is ``len(x)*eps``, where `eps` is the
1318
+ relative precision of the platform's float type, about 2e-16 in
1319
+ most cases.
1320
+ full : bool, optional
1321
+ Switch determining the nature of the return value. When ``False``
1322
+ (the default) just the coefficients are returned; when ``True``,
1323
+ diagnostic information from the singular value decomposition (used
1324
+ to solve the fit's matrix equation) is also returned.
1325
+ w : array_like, shape (`M`,), optional
1326
+ Weights. If not None, the weight ``w[i]`` applies to the unsquared
1327
+ residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1328
+ chosen so that the errors of the products ``w[i]*y[i]`` all have the
1329
+ same variance. When using inverse-variance weighting, use
1330
+ ``w[i] = 1/sigma(y[i])``. The default value is None.
1331
+
1332
+ Returns
1333
+ -------
1334
+ coef : ndarray, shape (`deg` + 1,) or (`deg` + 1, `K`)
1335
+ Polynomial coefficients ordered from low to high. If `y` was 2-D,
1336
+ the coefficients in column `k` of `coef` represent the polynomial
1337
+ fit to the data in `y`'s `k`-th column.
1338
+
1339
+ [residuals, rank, singular_values, rcond] : list
1340
+ These values are only returned if ``full == True``
1341
+
1342
+ - residuals -- sum of squared residuals of the least squares fit
1343
+ - rank -- the numerical rank of the scaled Vandermonde matrix
1344
+ - singular_values -- singular values of the scaled Vandermonde matrix
1345
+ - rcond -- value of `rcond`.
1346
+
1347
+ For more details, see `numpy.linalg.lstsq`.
1348
+
1349
+ Raises
1350
+ ------
1351
+ RankWarning
1352
+ Raised if the matrix in the least-squares fit is rank deficient.
1353
+ The warning is only raised if ``full == False``. The warnings can
1354
+ be turned off by:
1355
+
1356
+ >>> import warnings
1357
+ >>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
1358
+
1359
+ See Also
1360
+ --------
1361
+ numpy.polynomial.chebyshev.chebfit
1362
+ numpy.polynomial.legendre.legfit
1363
+ numpy.polynomial.laguerre.lagfit
1364
+ numpy.polynomial.hermite.hermfit
1365
+ numpy.polynomial.hermite_e.hermefit
1366
+ polyval : Evaluates a polynomial.
1367
+ polyvander : Vandermonde matrix for powers.
1368
+ numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
1369
+ scipy.interpolate.UnivariateSpline : Computes spline fits.
1370
+
1371
+ Notes
1372
+ -----
1373
+ The solution is the coefficients of the polynomial `p` that minimizes
1374
+ the sum of the weighted squared errors
1375
+
1376
+ .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
1377
+
1378
+ where the :math:`w_j` are the weights. This problem is solved by
1379
+ setting up the (typically) over-determined matrix equation:
1380
+
1381
+ .. math:: V(x) * c = w * y,
1382
+
1383
+ where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
1384
+ coefficients to be solved for, `w` are the weights, and `y` are the
1385
+ observed values. This equation is then solved using the singular value
1386
+ decomposition of `V`.
1387
+
1388
+ If some of the singular values of `V` are so small that they are
1389
+ neglected (and `full` == ``False``), a `~exceptions.RankWarning` will be
1390
+ raised. This means that the coefficient values may be poorly determined.
1391
+ Fitting to a lower order polynomial will usually get rid of the warning
1392
+ (but may not be what you want, of course; if you have independent
1393
+ reason(s) for choosing the degree which isn't working, you may have to:
1394
+ a) reconsider those reasons, and/or b) reconsider the quality of your
1395
+ data). The `rcond` parameter can also be set to a value smaller than
1396
+ its default, but the resulting fit may be spurious and have large
1397
+ contributions from roundoff error.
1398
+
1399
+ Polynomial fits using double precision tend to "fail" at about
1400
+ (polynomial) degree 20. Fits using Chebyshev or Legendre series are
1401
+ generally better conditioned, but much can still depend on the
1402
+ distribution of the sample points and the smoothness of the data. If
1403
+ the quality of the fit is inadequate, splines may be a good
1404
+ alternative.
1405
+
1406
+ Examples
1407
+ --------
1408
+ >>> import numpy as np
1409
+ >>> from numpy.polynomial import polynomial as P
1410
+ >>> x = np.linspace(-1,1,51) # x "data": [-1, -0.96, ..., 0.96, 1]
1411
+ >>> rng = np.random.default_rng()
1412
+ >>> err = rng.normal(size=len(x))
1413
+ >>> y = x**3 - x + err # x^3 - x + Gaussian noise
1414
+ >>> c, stats = P.polyfit(x,y,3,full=True)
1415
+ >>> c # c[0], c[1] approx. -1, c[2] should be approx. 0, c[3] approx. 1
1416
+ array([ 0.23111996, -1.02785049, -0.2241444 , 1.08405657]) # may vary
1417
+ >>> stats # note the large SSR, explaining the rather poor results
1418
+ [array([48.312088]), # may vary
1419
+ 4,
1420
+ array([1.38446749, 1.32119158, 0.50443316, 0.28853036]),
1421
+ 1.1324274851176597e-14]
1422
+
1423
+ Same thing without the added noise
1424
+
1425
+ >>> y = x**3 - x
1426
+ >>> c, stats = P.polyfit(x,y,3,full=True)
1427
+ >>> c # c[0], c[1] ~= -1, c[2] should be "very close to 0", c[3] ~= 1
1428
+ array([-6.73496154e-17, -1.00000000e+00, 0.00000000e+00, 1.00000000e+00])
1429
+ >>> stats # note the minuscule SSR
1430
+ [array([8.79579319e-31]),
1431
+ np.int32(4),
1432
+ array([1.38446749, 1.32119158, 0.50443316, 0.28853036]),
1433
+ 1.1324274851176597e-14]
1434
+
1435
+ """
1436
+ return pu._fit(polyvander, x, y, deg, rcond, full, w)
1437
+
1438
+
1439
+ def polycompanion(c):
1440
+ """
1441
+ Return the companion matrix of c.
1442
+
1443
+ The companion matrix for power series cannot be made symmetric by
1444
+ scaling the basis, so this function differs from those for the
1445
+ orthogonal polynomials.
1446
+
1447
+ Parameters
1448
+ ----------
1449
+ c : array_like
1450
+ 1-D array of polynomial coefficients ordered from low to high
1451
+ degree.
1452
+
1453
+ Returns
1454
+ -------
1455
+ mat : ndarray
1456
+ Companion matrix of dimensions (deg, deg).
1457
+
1458
+ Examples
1459
+ --------
1460
+ >>> from numpy.polynomial import polynomial as P
1461
+ >>> c = (1, 2, 3)
1462
+ >>> P.polycompanion(c)
1463
+ array([[ 0. , -0.33333333],
1464
+ [ 1. , -0.66666667]])
1465
+
1466
+ """
1467
+ # c is a trimmed copy
1468
+ [c] = pu.as_series([c])
1469
+ if len(c) < 2:
1470
+ raise ValueError('Series must have maximum degree of at least 1.')
1471
+ if len(c) == 2:
1472
+ return np.array([[-c[0] / c[1]]])
1473
+
1474
+ n = len(c) - 1
1475
+ mat = np.zeros((n, n), dtype=c.dtype)
1476
+ bot = mat.reshape(-1)[n::n + 1]
1477
+ bot[...] = 1
1478
+ mat[:, -1] -= c[:-1] / c[-1]
1479
+ return mat
1480
+
1481
+
1482
+ def polyroots(c):
1483
+ """
1484
+ Compute the roots of a polynomial.
1485
+
1486
+ Return the roots (a.k.a. "zeros") of the polynomial
1487
+
1488
+ .. math:: p(x) = \\sum_i c[i] * x^i.
1489
+
1490
+ Parameters
1491
+ ----------
1492
+ c : 1-D array_like
1493
+ 1-D array of polynomial coefficients.
1494
+
1495
+ Returns
1496
+ -------
1497
+ out : ndarray
1498
+ Array of the roots of the polynomial. If all the roots are real,
1499
+ then `out` is also real, otherwise it is complex.
1500
+
1501
+ See Also
1502
+ --------
1503
+ numpy.polynomial.chebyshev.chebroots
1504
+ numpy.polynomial.legendre.legroots
1505
+ numpy.polynomial.laguerre.lagroots
1506
+ numpy.polynomial.hermite.hermroots
1507
+ numpy.polynomial.hermite_e.hermeroots
1508
+
1509
+ Notes
1510
+ -----
1511
+ The root estimates are obtained as the eigenvalues of the companion
1512
+ matrix, Roots far from the origin of the complex plane may have large
1513
+ errors due to the numerical instability of the power series for such
1514
+ values. Roots with multiplicity greater than 1 will also show larger
1515
+ errors as the value of the series near such points is relatively
1516
+ insensitive to errors in the roots. Isolated roots near the origin can
1517
+ be improved by a few iterations of Newton's method.
1518
+
1519
+ Examples
1520
+ --------
1521
+ >>> import numpy.polynomial.polynomial as poly
1522
+ >>> poly.polyroots(poly.polyfromroots((-1,0,1)))
1523
+ array([-1., 0., 1.])
1524
+ >>> poly.polyroots(poly.polyfromroots((-1,0,1))).dtype
1525
+ dtype('float64')
1526
+ >>> j = complex(0,1)
1527
+ >>> poly.polyroots(poly.polyfromroots((-j,0,j)))
1528
+ array([ 0.00000000e+00+0.j, 0.00000000e+00+1.j, 2.77555756e-17-1.j]) # may vary
1529
+
1530
+ """ # noqa: E501
1531
+ # c is a trimmed copy
1532
+ [c] = pu.as_series([c])
1533
+ if len(c) < 2:
1534
+ return np.array([], dtype=c.dtype)
1535
+ if len(c) == 2:
1536
+ return np.array([-c[0] / c[1]])
1537
+
1538
+ m = polycompanion(c)
1539
+ r = la.eigvals(m)
1540
+ r.sort()
1541
+ return r
1542
+
1543
+
1544
+ #
1545
+ # polynomial class
1546
+ #
1547
+
1548
+ class Polynomial(ABCPolyBase):
1549
+ """A power series class.
1550
+
1551
+ The Polynomial class provides the standard Python numerical methods
1552
+ '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
1553
+ attributes and methods listed below.
1554
+
1555
+ Parameters
1556
+ ----------
1557
+ coef : array_like
1558
+ Polynomial coefficients in order of increasing degree, i.e.,
1559
+ ``(1, 2, 3)`` give ``1 + 2*x + 3*x**2``.
1560
+ domain : (2,) array_like, optional
1561
+ Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
1562
+ to the interval ``[window[0], window[1]]`` by shifting and scaling.
1563
+ The default value is [-1., 1.].
1564
+ window : (2,) array_like, optional
1565
+ Window, see `domain` for its use. The default value is [-1., 1.].
1566
+ symbol : str, optional
1567
+ Symbol used to represent the independent variable in string
1568
+ representations of the polynomial expression, e.g. for printing.
1569
+ The symbol must be a valid Python identifier. Default value is 'x'.
1570
+
1571
+ .. versionadded:: 1.24
1572
+
1573
+ """
1574
+ # Virtual Functions
1575
+ _add = staticmethod(polyadd)
1576
+ _sub = staticmethod(polysub)
1577
+ _mul = staticmethod(polymul)
1578
+ _div = staticmethod(polydiv)
1579
+ _pow = staticmethod(polypow)
1580
+ _val = staticmethod(polyval)
1581
+ _int = staticmethod(polyint)
1582
+ _der = staticmethod(polyder)
1583
+ _fit = staticmethod(polyfit)
1584
+ _line = staticmethod(polyline)
1585
+ _roots = staticmethod(polyroots)
1586
+ _fromroots = staticmethod(polyfromroots)
1587
+
1588
+ # Virtual properties
1589
+ domain = np.array(polydomain)
1590
+ window = np.array(polydomain)
1591
+ basis_name = None
1592
+
1593
+ @classmethod
1594
+ def _str_term_unicode(cls, i, arg_str):
1595
+ if i == '1':
1596
+ return f"·{arg_str}"
1597
+ else:
1598
+ return f"·{arg_str}{i.translate(cls._superscript_mapping)}"
1599
+
1600
+ @staticmethod
1601
+ def _str_term_ascii(i, arg_str):
1602
+ if i == '1':
1603
+ return f" {arg_str}"
1604
+ else:
1605
+ return f" {arg_str}**{i}"
1606
+
1607
+ @staticmethod
1608
+ def _repr_latex_term(i, arg_str, needs_parens):
1609
+ if needs_parens:
1610
+ arg_str = rf"\left({arg_str}\right)"
1611
+ if i == 0:
1612
+ return '1'
1613
+ elif i == 1:
1614
+ return arg_str
1615
+ else:
1616
+ return f"{arg_str}^{{{i}}}"