Python Forum
How to append arrays within a class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to append arrays within a class
#1
Essentially the class will act as a dictionary.

I need to append the string 'Time' to the self._keys list.
Also, I have a (32768, 1233) self._arr. I want to append a (32768, ) self._time to the self._arr. Such that the self._arr will become (32768, 1234).


class NFACDictionary(collections.abc.Mapping):
   
    def __init__(self, ecfgFilename, eudFilename, timeFilename):
        keys = self._key_data(ecfgFilename)
        array = self._read_data(eudFilename)
        time = self._read_time_data(timeFilename)
        #append 'Time' to self._keys.  Append time values to self._arr. <---- This is what I'm trying to do.
        self._keys = keys
        self._arr = array
        self._time = time
Reply
#2
Are self ._keys/._arr/._time lists? Just use .append().
Reply
#3
_keys is a list.

_arr and _time are numpy arrays.
Reply
#4
You might want to look at collections.UserDict. A subclass of that should be easier to implement. The collections.abc classes are usually used for testing classes. To do it the way you're doing it, you also need to implement all of the abstract methods. And keys is a method of Mapping, but it looks like you're replacing it with a list.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  comparing floating point arrays to arrays of integers in Numpy amjass12 0 1,625 Jul-26-2021, 11:58 AM
Last Post: amjass12
  Numpy arrays and compatability with Fortran arrays merrittr 0 1,872 Sep-03-2019, 03:54 AM
Last Post: merrittr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020