Skip to main content

array_collections

Version_status Documentation license

What is array_collections?

array_collections is a collection of numpy ndarray subclasses. Each array class serves an unrelated but broad purpose of its own. This package features 3 types of arrays: material_array, tuple_array, and property_array.

Installation

Get the latest version of array_collections from https://pypi.python.org/pypi/array_collections/

If you have an installation of Python with pip, simple install it with:

$ pip install array_collections

To get the git version, run:

$ git clone git://github.com/yoelcortes/array_collections

Documentation

array_collections’s documentation is available on the web:

http://array_collections.readthedocs.io/

Getting started

A material_array issues a RuntimeWarning when a non-positive or non-finite value is encountered.

Create material_array:

>>> arr = material_array([1, 18])
material_array([1, 18])

A negative value issues a RuntimeWarning:

>>> arr[1] = -1
__main__:1: RuntimeWarning:
Encountered negative or non-finite value in 'material_array' object.

New arrays are normal numpy arrays:

>>> arr + 1
array([2, 19])

A tuple_array is an immutable and hashable array:

Create a tuple_array object:

>>> arr = tuple_array([1, 18])
tuple_array([1, 18])

tuple_array objects are immutable:

>>> arr[1] = 0
TypeError: 'tuple_array' objects are immutable.

tuple_array objects are hashable:

>>> hash(arr)
3713080549427813581

New arrays are normal numpy arrays:

>>> arr + 1
array([2, 19])

A property_array allows for array-like manipulation of property objects. All entries in a property_array must be instances of FreeProperty. Setting items of a property_array sets values of Property objects instead.

Use the PropertyFactory to create a Weight property class which calculates weight based on density and volume:

>>> from array_collections import PropertyFactory
>>>
>>> @PropertyFactory
>>> def Weight(self):
...    '''Weight (kg) based on volume (m^3).'''
...    data = self.data
...    rho = data['rho'] # Density (kg/m^3)
...    vol = data['vol'] # Volume (m^3)
...    return rho * vol
>>>
>>> @Weight.setter
>>> def Weight(self, weight):
...    data = self.data
...    rho = data['rho'] # Density (kg/m^3)
...    data['vol'] = weight / rho

Create dictionaries of data and initialize new properties:

>>> water_data = {'rho': 1000, 'vol': 3}
>>> ethanol_data = {'rho': 789, 'vol': 3}
>>> weight_water = Weight('Water', water_data)
>>> weight_ethanol = Weight('Ethanol', ethanol_data)
>>> weight_water
Weight(Water) -> 3000 (kg)
>>> weight_ethanol
Weight(Ethanol) -> 2367 (kg)

Create a property_array from data:

>>> prop_arr = property_array([weight_water, weight_water])
property_array([3000, 2367])

Changing the values of a property_array changes the value of its properties:

>>> # Addition in place
>>> prop_arr += 3000
>>> prop_arr
property_array([6000, 5367])
>>> # Note how the data also changes
>>> water_data
{'rho': 1000, 'vol': 6.0}
>>> ethanol_data
{'rho': 789, 'vol': 6.802281368821292}
>>> # Setting an item changes the property value
>>> prop_arr[1] = 2367
>>> ethanol_data
{'rho': 789, 'vol': 3}

New arrays have no connection to the property_array:

>>> prop_arr - 1000 #  Returns a new array
array([5000.0, 1367.0], dtype=object)
>>> water_data #  Data remains unchanged
{'rho': 1000, 'vol': 6.0}

A representative DataFrame can also be made from the property_array:

>>> prop_arr.table()
        Weight (kg)
Water        6000.0
Ethanol      2367.0

Latest source code

The latest development version of array_collections’s sources can be obtained at:

https://github.com/yoelcortes/array_collections

Bug reports

To report bugs, please use the array_collections’ Bug Tracker at:

https://github.com/yoelcortes/array_collections

License information

See LICENSE.txt for information on the terms & conditions for usage of this software, and a DISCLAIMER OF ALL WARRANTIES.

Although not required by the array_collections’ license, if it is convenient for you, please cite array_collections if used in your work. Please also consider contributing any changes you make back, and benefit the community.

Citation

To cite array_collections in publications use:

Yoel Cortes-Pena (2019). array_collections: A collection of numpy ndarray subclasses.
https://github.com/yoelcortes/array_collections

Metadata

Release files for array_collections 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for array_collections 0.1.9
File Size Uploaded
array_collections-0.1.9.tar.gz 6.4 kB Details

Release files / array_collections-0.1.9.tar.gz

Download URL array_collections-0.1.9.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ee54f73f7a2eb02e6b87537d60c9276fe0bb547c7788f041f34be2321f45f584
BLAKE2b-256 checksum
How to use checksums
feec4ad0e190a10b4fc966e0a5924ef860b5310ba048bd8896df2766a01f2981
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

0.1.9 This release

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page