Paul Krill
Editor at Large

NumPy 1.20 introduces type annotations

news
Feb 26, 20212 mins

Major upgrade to the scientific package for Python also features expanded use of SIMD, increasing the execution speed of universal functions.

Data science
Credit: Nick Hoffman

NumPy 1.20.0, described as the largest-ever release of the scientific computing package for Python, has arrived, introducing new capabilities such as type annotations and expanded use of SIMD (single instruction, multiple data).

Release notes for NumPy 1.20.0 indicate type annotations have been added for large parts of NumPy. There also is a new numpy.typing module containing useful types for end users. Currently available types include ArrayLike, for objects that can be coerced into an array, and DtypeLike, for objects that can be coerced into a dtype.

Wider use of SIMD in NumPy increases execution speed of universal functions (ufuncs). Work was done to introduce universal functions that will ease the use of modern features on different hardware platforms. In addition, improvements have been made to pave the way to NEP-38 (NumPy Enhancement Proposal) SIMD performance optimizations.

Other additions and improvements in NumPy 1.20.0 include:

  • Preliminary work on changing the dtype (data type object) and casting implementations to provide for extending dtypes.
  • Preliminary support for version 3.0 of the Cython language for writing C extensions for Python.
  • The randon.Generator class has a new permuted function.
  • Indexing errors shall be reported even when the index result is empty.
  • A where keyword argument has been added, to only consider specified elements or subaxes from an array in the Boolean evaluation of all and any.
  • Types in numpy.typing now can be imported at runtime.
  • The sliding_window_view function offers a sliding window view for NumPy arrays.
  • When creating or assigning to arrays, in all revelant cases NumPy scalars now will be cast identically to NumPy arrays
  • Use of aliases of built-in types such as np.int has been deprecated.
  • Inexact matches for mode and searchside have been deprecated.
  • Cleanups have been made pertaining to removing Python 2.7, with code readability improved and technical debt removed.

Installation instructions for NumPy can be found at numpy.org. Language versions supported by NumPy 1.20.0 include Python 3.7 through Python 3.9; support has been dropped for Python 3.6.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author