Esempio n. 1
0
def list_indices_to_index_array(list_indices):
    """
        Converts a list of tuple indices to numpy index array.

        Args:
            list_indices(list):    a list of indices corresponding to some
                                   array object

        Returns:
            chain_gen(tuple):      a tuple containing a numpy array for each
                                   index

        Examples:
            >>> list_indices_to_index_array([])
            ()

            >>> list_indices_to_index_array([(1,2)])
            (array([1]), array([2]))

            >>> list_indices_to_index_array([(1, 2), (5, 7), (33, 2)])
            (array([ 1,  5, 33]), array([2, 7, 2]))
    """

    # Combines the indices so that one dimension is represented by each list.
    # Then converts this to a tuple numpy.ndarrays.
    return(tuple(numpy.array(list(izip(*list_indices)))))
Esempio n. 2
0
    def add_phases(self, entries, energies):
        """Function to set many phase energies.

        Parameters
        ----------
        entries : array-like
            A list of CompositionEntry's.

        energies : array-like
            A list of energy values as floats.

        """
        if isinstance(energies,pd.DataFrame):
            if energies.shape[1] == 1:
                energies = energies.values
            else:
                msg = "a dataframe with one column is required"
                raise Exception(msg)
        if isinstance(entries,pd.DataFrame):
            if entries.shape[1] == 1:
                entries = entries.values
            else:
                msg = "a dataframe with one column is required"
                raise Exception(msg)

        for entry,energy in izip(entries, energies):
            # if has measurement
            self.add_phase(entry, energy)
Esempio n. 3
0
def filled_stringify_enumerate(new_iter):
    """
        Takes each element yielded by new_iter and reverses it using reversed.

        Args:
            new_iter(iter):        an iterator to use for enumeration over.

        Returns:
            (generator object):    an iterator over the reversed elements.

        Examples:
            >>> filled_stringify_enumerate([5, 7]) #doctest: +ELLIPSIS
            <generator object filled_stringify_enumerate at 0x...>

            >>> list(filled_stringify_enumerate([]))
            []

            >>> list(filled_stringify_enumerate(irange(5)))
            [(0, '0', 0), (1, '1', 1), (2, '2', 2), (3, '3', 3), (4, '4', 4)]

            >>> list(filled_stringify_enumerate(irange(2, 5)))
            [(0, '0', 2), (1, '1', 3), (2, '2', 4)]

            >>> list(filled_stringify_enumerate([5]))
            [(0, '0', 5)]

            >>> list(filled_stringify_enumerate([5, 7]))
            [(0, '0', 5), (1, '1', 7)]

            >>> list(filled_stringify_enumerate(iter([5, 7])))
            [(0, '0', 5), (1, '1', 7)]

            >>> list(filled_stringify_enumerate(range(11)))
            [(0, '00', 0), (1, '01', 1), (2, '02', 2), (3, '03', 3), (4, '04', 4), (5, '05', 5), (6, '06', 6), (7, '07', 7), (8, '08', 8), (9, '09', 9), (10, '10', 10)]
    """

    new_list = new_iter
    new_list_index_gen = None
    try:
        new_list_index_gen = irange(len(new_list))
    except TypeError:
        new_list = list(new_list)
        new_list_index_gen = irange(len(new_list))

    new_list_index_gen_stringified = filled_stringify_numbers(
        new_list_index_gen, include_numbers=True
    )

    for (i, i_str), each in izip(new_list_index_gen_stringified, new_list):
        yield ((i, i_str, each))
Esempio n. 4
0
def each_cons(xs, n):
    return izip(*(xs[i:] for i in range(n)))
Esempio n. 5
0
 def iteritems(self):
     return izip(self.iterkeys(), self.itervalues())
Esempio n. 6
0
 def iteritems(self):
     return izip(self.iterkeys(), self.itervalues())