np – create numpy arrays as np[1,3,5], and more
np = numpy + handy tools
For the numerical Python package numpy itself, see http://www.numpy.org/.
The idea of np is to provide a way of creating numpy arrays with a compact syntax and without an explicit function call. Making the module name np subscriptable, while still keeping it essentially an alias for numpy, does this in a clean way.
Any feedback is very welcome: koos.zevenhoven@aalto.fi.
Getting Started
Requirements
Works best with Python 3.5+ (Tested also with 3.4 and 2.7)
numpy (you should install this using your python package manager like conda or pip)
Installation
np can be installed with pip:
$ pip install np
or directly from the source code:
$ git clone https://github.com/k7hoven/np.git
$ cd np
$ python setup.py install
Basic Usage
Even before the np tool, a popular style of using numpy has been to import it as np:
>>> import numpy as np
>>> my_array = np.array([3, 4, 5])
>>> my_2d_array = np.array([[1, 2], [3, 4]])
The most important feature of np is to make the creation of arrays less verbose, while everything else works as before. The above code becomes:
>>> import np
>>> my_array = np[3, 4, 5]
>>> my_2d_array = np[[1, 2], [3, 4]]
As you can see from the above example, you can create numpy arrays by subscripting the np module. Since most people would have numpy imported as np anyway, this requires no additional names to clutter the namespace. Also, the syntax np[1,2,3] resembles the syntax for bytes literals, b"asd".
The np package also provides a convenient way of ensuring something is a numpy array, that is, a shortcut to numpy.asanyarray():
>>> import np
>>> mylist = [1, 3, 5]
>>> mylist + [7, 9, 11]
[1, 3, 5, 7, 9, 11]
>>> np(mylist) + [7, 9, 11]
array([8, 12, 16])
As an experimental feature, there are also shortcuts for giving the arrays a specific data type (numpy dtype):
>>> np[1, 2, 3]
array([1, 2, 3])
>>> np.f[1, 2, 3]
array([ 1., 2., 3.])
>>> np.f2[1, 2, 3]
array([ 1., 2., 3.], dtype=float16)
>>> np.u4[1, 2, 3]
array([1, 2, 3], dtype=uint32)
>>> np.c[1, 2, 3]
array([ 1.+0.j, 2.+0.j, 3.+0.j])
Changelog
0.2.0 (2016-03-29)
Quick types are now np.i, np.f, np.u, np.c, or with the number of /bytes/ per value appended: np.i4 -> int32, np.u2 -> uint16, np.c16 -> complex128, … (still somewhat experimental)
Removed the old np.i8 and np.ui8 which represented 8-bit types, which was inconsistent with short numpy dtype names which correspond to numbers of bytes. The rest of the bit-based shortcuts are deprecated and will be removed later.
Handle Python versions >=3.5 better; now even previously imported plain numpy module objects become the exact same object as np.
Tests for all np functionality
Ridiculously slow tests that runs the numpy test suite several times to make sure that np does not affect numpy functionality.
Remove numpy from requirements and give a meaningful error instead if numpy is missing (i.e. install it using your package manager like conda or pip)
Better reprs for subscriptable array creator objects and the np/numpy module.
0.1.4 (2016-01-26)
Bug fix
0.1.2 (2015-06-17)
Improved experimental dtype shortcuts: np.f[1,2], np.i32[1,2], etc.
0.1.1 (2015-06-17)
PyPI-friendly readme
0.1.0 (2015-06-17)
First distributable version
Easy arrays such as np[[1,2],[3,4]]
Shortcut for np.asanyarray(obj): np(obj)
Experimental dtype shortcuts: np.f64[[1,2],[3,4]]
Metadata
Release files for np 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| np-0.2.0.tar.gz | 5.2 kB | Without provenance | Details for np-0.2.0.tar.gz |
Release files / np-0.2.0.tar.gz
| Download URL | np-0.2.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd655d688ebdaa4b00ef625e63e9b28d7f4fae6fb921ef9e65e5ca8da9dad9d7
|
|
BLAKE2b-256 checksum How to use checksums |
7a40c11a7d07879d514de7f271182903647566afc13abf21e9ac48a0fcc251ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for np 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.