PitchClassVector

class pitchtools.PitchClassVector(items=None, item_class=None)

Pitch-class vector.

Example 1.

>>> vector = pitchtools.PitchClassVector(
...     items=[7, 6, -2, -3, -3, 0, 1, 14, 15, 16, 16],
...     item_class=pitchtools.NumberedPitchClass,
...     )
>>> items = sorted(vector.items())
>>> for pitch_class, count in items:
...     print(pitch_class, count)
0 1
1 1
2 1
3 1
4 2
6 1
7 1
9 2
10 1

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_datastructuretools { graph [label=datastructuretools]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" [color=3, group=2, label=TypedCollection, shape=oval, style=bold]; "abjad.tools.datastructuretools.TypedCounter.TypedCounter" [color=3, group=2, label=TypedCounter, shape=box]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" -> "abjad.tools.datastructuretools.TypedCounter.TypedCounter"; } subgraph cluster_pitchtools { graph [label=pitchtools]; "abjad.tools.pitchtools.PitchClassVector.PitchClassVector" [color=black, fontcolor=white, group=3, label=<<B>PitchClassVector</B>>, shape=box, style="filled, rounded"]; "abjad.tools.pitchtools.Vector.Vector" [color=4, group=3, label=Vector, shape=oval, style=bold]; "abjad.tools.pitchtools.Vector.Vector" -> "abjad.tools.pitchtools.PitchClassVector.PitchClassVector"; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.datastructuretools.TypedCollection.TypedCollection"; "abjad.tools.datastructuretools.TypedCounter.TypedCounter" -> "abjad.tools.pitchtools.Vector.Vector"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

clear() Clears typed counter.
copy() Copies typed counter.
elements() Elements in typed counter.
from_selection(class_, selection[, item_class]) Makes pitch-class vector from selection.
item_class Item class to coerce items into.
items() Items in typed counter.
keys() Iterates keys in typed counter.
most_common([n]) Please document.
subtract([iterable]) Stracts iterable from typed counter.
update([iterable]) Updates typed counter with iterable.
values() Iterates values in typed counter.
viewitems() Please document.
viewkeys() Please document.
viewvalues() Please document.
__add__(expr) Adds typed counter to expr.
__and__(expr) Logical AND of typed counter and expr.
__contains__(item) Is true when typed collection container item.
__delitem__(item) Deletes item from typed counter.
__eq__(expr) Is true when expr is a typed collection with items that compare equal to those of this typed collection.
__format__([format_specification]) Gets format of pitch-class vector.
__getitem__(item) Gets item from typed counter.
__hash__() Hashes typed collection.
__iter__() Iterates typed collection.
__len__() Length of typed collection.
__missing__(item) Returns zero.
__ne__(expr) Is true when expr is not a typed collection with items equal to this typed collection.
__or__(expr) Logical OR of typed counter and expr.
__repr__() Gets interpreter representation of pitch-class vector.
__setitem__(item, value) Sets typed counter item to value.
__str__() String representation of vector.
__sub__(expr) Subtracts expr from typed counter.

Read-only properties

(TypedCollection).item_class

Item class to coerce items into.

Methods

(TypedCounter).clear()

Clears typed counter.

Returns none.

(TypedCounter).copy()

Copies typed counter.

Returns new typed counter.

(TypedCounter).elements()

Elements in typed counter.

(TypedCounter).items()

Items in typed counter.

Returns tuple.

(TypedCounter).keys()

Iterates keys in typed counter.

(TypedCounter).most_common(n=None)

Please document.

(TypedCounter).subtract(iterable=None, **kwargs)

Stracts iterable from typed counter.

(TypedCounter).update(iterable=None, **kwargs)

Updates typed counter with iterable.

(TypedCounter).values()

Iterates values in typed counter.

(TypedCounter).viewitems()

Please document.

(TypedCounter).viewkeys()

Please document.

(TypedCounter).viewvalues()

Please document.

Class & static methods

classmethod PitchClassVector.from_selection(class_, selection, item_class=None)

Makes pitch-class vector from selection.

Returns pitch-class vector.

Special methods

(TypedCounter).__add__(expr)

Adds typed counter to expr.

Returns new typed counter.

(TypedCounter).__and__(expr)

Logical AND of typed counter and expr.

Returns new typed counter.

(TypedCollection).__contains__(item)

Is true when typed collection container item. Otherwise false.

Returns true or false.

(TypedCounter).__delitem__(item)

Deletes item from typed counter.

Returns none.

(TypedCollection).__eq__(expr)

Is true when expr is a typed collection with items that compare equal to those of this typed collection. Otherwise false.

Returns true or false.

PitchClassVector.__format__(format_specification='')

Gets format of pitch-class vector.

>>> vector = pitchtools.PitchClassVector(
...     items=[7, 6, -2, -3, -3, 0, 1, 14, 15, 16, 16],
...     item_class=pitchtools.NumberedPitchClass,
...     )
>>> print(format(vector))
pitchtools.PitchClassVector(
    {
        pitchtools.NumberedPitchClass(0): 1,
        pitchtools.NumberedPitchClass(1): 1,
        pitchtools.NumberedPitchClass(2): 1,
        pitchtools.NumberedPitchClass(3): 1,
        pitchtools.NumberedPitchClass(4): 2,
        pitchtools.NumberedPitchClass(6): 1,
        pitchtools.NumberedPitchClass(7): 1,
        pitchtools.NumberedPitchClass(9): 2,
        pitchtools.NumberedPitchClass(10): 1,
        },
    item_class=pitchtools.NumberedPitchClass,
    )

Returns string.

(TypedCounter).__getitem__(item)

Gets item from typed counter.

Returns item.

(TypedCollection).__hash__()

Hashes typed collection.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedCollection).__len__()

Length of typed collection.

Returns nonnegative integer.

(TypedCounter).__missing__(item)

Returns zero.

Returns zero.

(TypedCollection).__ne__(expr)

Is true when expr is not a typed collection with items equal to this typed collection. Otherwise false.

Returns true or false.

(TypedCounter).__or__(expr)

Logical OR of typed counter and expr.

Returns new typed counter.

PitchClassVector.__repr__()

Gets interpreter representation of pitch-class vector.

Example 1. Gets interpreter representation of pitch-class vector:

>>> vector = pitchtools.PitchClassVector(
...     items=[7, 6, -2, -3, -3, 0, 1, 14, 15, 16, 16],
...     item_class=pitchtools.NumberedPitchClass,
...     )
>>> vector
PitchClassVector({0: 1, 1: 1, 2: 1, 3: 1, 4: 2, 6: 1, 7: 1, 9: 2, 10: 1}, item_class=NumberedPitchClass)

Example 2. Initializes from interpreter representation of pitch-class vector:

>>> pitchtools.PitchClassVector(vector)
PitchClassVector({0: 1, 1: 1, 2: 1, 3: 1, 4: 2, 6: 1, 7: 1, 9: 2, 10: 1}, item_class=NumberedPitchClass)

Returns string.

(TypedCounter).__setitem__(item, value)

Sets typed counter item to value.

Returns none.

(Vector).__str__()

String representation of vector.

Returns string.

(TypedCounter).__sub__(expr)

Subtracts expr from typed counter.

Returns new typed counter.