ntv-numpy.ntv_numpy.xndarray

@author: Philippe@loco-labs.io

The xndarray module is part of the ntv-numpy.ntv_numpy package (specification document).

It contains the classes Xndarray for the labeled multidimensional array.

For more information, see the user guide or the github repository.

  1# -*- coding: utf-8 -*-
  2"""
  3@author: Philippe@loco-labs.io
  4
  5The `xndarray` module is part of the `ntv-numpy.ntv_numpy` package ([specification document](
  6https://loco-philippe.github.io/ES/JSON%20semantic%20format%20(JSON-NTV).htm)).
  7
  8It contains the classes `Xndarray` for the labeled multidimensional array.
  9
 10For more information, see the
 11[user guide](https://loco-philippe.github.io/ntv-numpy/docs/user_guide.html)
 12 or the [github repository](https://github.com/loco-philippe/ntv-numpy).
 13"""
 14
 15import json
 16from json_ntv import Ntv
 17from ntv_numpy.ndarray import Ndarray, Nutil, NdarrayError
 18
 19
 20class Xndarray:
 21    ''' Representation of a labelled multidimensional Array
 22
 23    *Attributes :*
 24    - **name** :  string - name of the Xndarray
 25    - **add_name** :  string - additional name of the Xndarray
 26    - **nda**: Ndarray - ndarray data
 27    - **links**: list of string - links to other Xndarray
 28    - **meta** : JsonValue - informations
 29
 30    *dynamic values (@property)*
 31    - `darray`
 32    - `ndarray`
 33    - `uri`
 34    - `shape`
 35    - `ntv_type`
 36    - `info`
 37    - `mode`
 38    - `xtype`
 39    - `full_name`
 40    - `json_name`
 41
 42    *methods*
 43    - `to_json`
 44    - `read_json (static method)`
 45    - `set_ndarray`
 46    '''
 47
 48    def __init__(self, full_name, nda=None, links=None,
 49                 meta=None):
 50        '''Xndarray constructor.
 51
 52        *Parameters*
 53
 54        - **full_name**: string (default None) - name with additional name
 55        - **nda** : Ndarray (default None) - data
 56        - **links**: List of string (default None) - dims or other names of associated Xndarray
 57        - **ntv_type**: string (default None) - ntv_type to apply to data
 58        - **meta**: dict (default None) - information
 59        '''
 60        # print('init xnd', full_name, nda.to_json(), links, meta)
 61        if isinstance(full_name, Xndarray):
 62            self.name = full_name.name
 63            self.add_name = full_name.add_name
 64            self.nda = full_name.nda
 65            self.links = full_name.links
 66            self.meta = full_name.meta
 67            return
 68        self.name, self.add_name = Nutil.split_name(full_name)
 69        self.nda = Ndarray(nda) if not nda is None else None
 70        self.links = sorted(links) if links else None
 71        self.meta = meta if meta else None
 72        if self.meta is None and self.nda is None:
 73            raise NdarrayError('A Xndarray has to have metadata or Ndarray')
 74
 75    def __repr__(self):
 76        '''return classname and number of value'''
 77        return self.__class__.__name__ + '[' + self.full_name + ']'
 78
 79    def __str__(self):
 80        '''return json string format'''
 81        return json.dumps(self.to_json())
 82
 83    def __eq__(self, other):
 84        ''' equal if attributes are equal'''
 85        if self.name != other.name or self.add_name != other.add_name:
 86            return False
 87        if self.links != other.links or self.meta != other.meta:
 88            return False
 89        if self.nda is None and other.nda is None:
 90            return True
 91        if self.nda is None or other.nda is None:
 92            return False
 93        return self.nda == other.nda
 94
 95    def __len__(self):
 96        ''' len of ndarray'''
 97        return len(self.nda) if self.nda is not None else 0
 98
 99    def __contains__(self, item):
100        ''' item of ndarray values'''
101        return item in self.nda if self.nda is not None else None
102
103    def __getitem__(self, ind):
104        ''' return ndarray value item'''
105        if self.nda is None:
106            return None
107        if isinstance(ind, tuple):
108            return [self.nda[i] for i in ind]
109            # return [copy(self.values[i]) for i in ind]
110        return self.nda[ind]
111        # return copy(self.values[ind])
112
113    def __copy__(self):
114        ''' Copy all the data '''
115        return self.__class__(self)
116
117    @property
118    def darray(self):
119        '''return the darray of the ndarray'''
120        return self.nda.darray if self.nda is not None else None
121
122    @property
123    def ndarray(self):
124        '''return the darray of the ndarray'''
125        return self.nda.ndarray if self.nda is not None else None
126
127    @property
128    def uri(self):
129        '''return the uri of the ndarray'''
130        return self.nda.uri if self.nda is not None else None
131
132    @property
133    def shape(self):
134        '''return the shape of the ndarray'''
135        return self.nda.shape if self.nda is not None else None
136
137    @property
138    def ntv_type(self):
139        '''return the ntv_type of the ndarray'''
140        return self.nda.ntv_type if self.nda is not None else None
141
142    @property
143    def mode(self):
144        '''return the mode of the ndarray'''
145        return self.nda.mode if self.nda is not None else 'undefined'
146
147    @property
148    def info(self):
149        ''' infos of the Xndarray'''
150        inf = {'name': self.full_name}
151        inf['length'] = len(self)
152        if self.nda:
153            inf['mode'] = self.mode
154            inf['ntvtype'] = self.ntv_type
155            inf['shape'] = self.shape
156        inf['xtype'] = self.xtype
157        inf['links'] = self.links
158        return {key: val for key, val in inf.items() if val}
159
160    @property
161    def xtype(self):
162        '''nature of the Xndarray (undefined, namedarray, variable, additional,
163        inconsistent)'''
164        match [self.links, self.add_name, self.mode]:
165            case [_, _, 'inconsistent']:
166                return 'inconsistent'
167            case [_, _, 'undefined']:
168                return 'metadata'
169            case [None, '', _]:
170                return 'namedarray'
171            case [_, '', _]:
172                return 'variable'
173            case [_, str(), _]:
174                return 'additional'
175            case _:
176                return 'inconsistent'
177
178    @property
179    def full_name(self):
180        '''concatenation of name and additional name'''
181        add_name = '.' + self.add_name if self.add_name else ''
182        return self.name + add_name
183
184    @property
185    def json_name(self):
186        '''concatenation of full_name and ntv_type'''
187        add_ntv_type = ':' + self.ntv_type if self.ntv_type else ''
188        return self.full_name + add_ntv_type
189
190    @staticmethod
191    def read_json(jsn, **kwargs):
192        ''' convert json data into a Xndarray.
193
194        *Parameters*
195
196        - **convert** : boolean (default True) - If True, convert json data with
197        non Numpy ntv_type into data with python type
198        '''
199        option = {'convert': True} | kwargs
200        jso = json.loads(jsn) if isinstance(jsn, str) else jsn
201        value, full_name = Ntv.decode_json(jso)[:2]
202
203        meta = links = nda = None
204        match value:
205            case str(meta) | dict(meta): ...
206            case [list(nda)]: ...
207            case [list(nda), list(links)]: ...
208            case [list(nda), dict(meta)] | [list(nda), str(meta)]: ...
209            case [list(nda), list(links), dict(meta)]: ...
210            case [list(nda), list(links), str(meta)]: ...
211            case _:
212                return None
213        nda = Ndarray.read_json(nda, **option) if nda else None
214        return Xndarray(full_name, links=links, meta=meta, nda=nda)
215
216    def set_ndarray(self, ndarray, nda_uri=True):
217        '''set a new ndarray (nda) and return the result (True, False)
218
219        *Parameters*
220
221        - **ndarray** : string, list, np.ndarray, Ndarray - data to include
222        - **nda_uri** : boolean (default True) - if True, existing shape and
223        ntv_type are not updated (but are created if not existing)'''
224        ndarray = Ndarray(ndarray)
225        if not self.nda is None:
226            return self.nda.update(ndarray, nda_uri=nda_uri)
227        self.nda = ndarray
228        return True
229
230    def to_json(self, **kwargs):
231        ''' convert a Xndarray into json-value.
232
233        *Parameters*
234
235        - **encoded** : Boolean (default False) - json-value if False else json-text
236        - **header** : Boolean (default True) - including xndarray type
237        - **noname** : Boolean (default False) - including data type and name if False
238        - **notype** : Boolean (default False) - including data type if False
239        - **novalue** : Boolean (default False) - including value if False
240        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
241        - **format** : string (default 'full') - representation format of the ndarray,
242        - **extension** : string (default None) - type extension
243        '''
244        option = {'notype': False, 'format': 'full',
245                  'noshape': True, 'header': True, 'encoded': False,
246                  'novalue': False, 'noname': False} | kwargs
247        if not option['format'] in ['full', 'complete']:
248            option['noshape'] = False
249        opt_nda = option | {'header': False}
250        # nda_str = Ndarray.to_json(self.nda,
251        nda_str = self.nda.to_json(**opt_nda) if not self.nda is None else None
252        lis = [nda_str, self.links, self.meta]
253        lis = [val for val in lis if not val is None]
254        return Nutil.json_ntv(None if option['noname'] else self.full_name,
255                              None if option['noname'] else 'xndarray',
256                              lis[0] if lis == [self.meta] else lis,
257                              header=option['header'], encoded=option['encoded'])
258
259    def _to_json(self):
260        '''return dict of attributes'''
261        return {'name': self.name, 'ntv_type': self.ntv_type, 'uri': self.uri,
262                'nda': self.nda, 'meta': self.meta, 'links': self.links}
class Xndarray:
 21class Xndarray:
 22    ''' Representation of a labelled multidimensional Array
 23
 24    *Attributes :*
 25    - **name** :  string - name of the Xndarray
 26    - **add_name** :  string - additional name of the Xndarray
 27    - **nda**: Ndarray - ndarray data
 28    - **links**: list of string - links to other Xndarray
 29    - **meta** : JsonValue - informations
 30
 31    *dynamic values (@property)*
 32    - `darray`
 33    - `ndarray`
 34    - `uri`
 35    - `shape`
 36    - `ntv_type`
 37    - `info`
 38    - `mode`
 39    - `xtype`
 40    - `full_name`
 41    - `json_name`
 42
 43    *methods*
 44    - `to_json`
 45    - `read_json (static method)`
 46    - `set_ndarray`
 47    '''
 48
 49    def __init__(self, full_name, nda=None, links=None,
 50                 meta=None):
 51        '''Xndarray constructor.
 52
 53        *Parameters*
 54
 55        - **full_name**: string (default None) - name with additional name
 56        - **nda** : Ndarray (default None) - data
 57        - **links**: List of string (default None) - dims or other names of associated Xndarray
 58        - **ntv_type**: string (default None) - ntv_type to apply to data
 59        - **meta**: dict (default None) - information
 60        '''
 61        # print('init xnd', full_name, nda.to_json(), links, meta)
 62        if isinstance(full_name, Xndarray):
 63            self.name = full_name.name
 64            self.add_name = full_name.add_name
 65            self.nda = full_name.nda
 66            self.links = full_name.links
 67            self.meta = full_name.meta
 68            return
 69        self.name, self.add_name = Nutil.split_name(full_name)
 70        self.nda = Ndarray(nda) if not nda is None else None
 71        self.links = sorted(links) if links else None
 72        self.meta = meta if meta else None
 73        if self.meta is None and self.nda is None:
 74            raise NdarrayError('A Xndarray has to have metadata or Ndarray')
 75
 76    def __repr__(self):
 77        '''return classname and number of value'''
 78        return self.__class__.__name__ + '[' + self.full_name + ']'
 79
 80    def __str__(self):
 81        '''return json string format'''
 82        return json.dumps(self.to_json())
 83
 84    def __eq__(self, other):
 85        ''' equal if attributes are equal'''
 86        if self.name != other.name or self.add_name != other.add_name:
 87            return False
 88        if self.links != other.links or self.meta != other.meta:
 89            return False
 90        if self.nda is None and other.nda is None:
 91            return True
 92        if self.nda is None or other.nda is None:
 93            return False
 94        return self.nda == other.nda
 95
 96    def __len__(self):
 97        ''' len of ndarray'''
 98        return len(self.nda) if self.nda is not None else 0
 99
100    def __contains__(self, item):
101        ''' item of ndarray values'''
102        return item in self.nda if self.nda is not None else None
103
104    def __getitem__(self, ind):
105        ''' return ndarray value item'''
106        if self.nda is None:
107            return None
108        if isinstance(ind, tuple):
109            return [self.nda[i] for i in ind]
110            # return [copy(self.values[i]) for i in ind]
111        return self.nda[ind]
112        # return copy(self.values[ind])
113
114    def __copy__(self):
115        ''' Copy all the data '''
116        return self.__class__(self)
117
118    @property
119    def darray(self):
120        '''return the darray of the ndarray'''
121        return self.nda.darray if self.nda is not None else None
122
123    @property
124    def ndarray(self):
125        '''return the darray of the ndarray'''
126        return self.nda.ndarray if self.nda is not None else None
127
128    @property
129    def uri(self):
130        '''return the uri of the ndarray'''
131        return self.nda.uri if self.nda is not None else None
132
133    @property
134    def shape(self):
135        '''return the shape of the ndarray'''
136        return self.nda.shape if self.nda is not None else None
137
138    @property
139    def ntv_type(self):
140        '''return the ntv_type of the ndarray'''
141        return self.nda.ntv_type if self.nda is not None else None
142
143    @property
144    def mode(self):
145        '''return the mode of the ndarray'''
146        return self.nda.mode if self.nda is not None else 'undefined'
147
148    @property
149    def info(self):
150        ''' infos of the Xndarray'''
151        inf = {'name': self.full_name}
152        inf['length'] = len(self)
153        if self.nda:
154            inf['mode'] = self.mode
155            inf['ntvtype'] = self.ntv_type
156            inf['shape'] = self.shape
157        inf['xtype'] = self.xtype
158        inf['links'] = self.links
159        return {key: val for key, val in inf.items() if val}
160
161    @property
162    def xtype(self):
163        '''nature of the Xndarray (undefined, namedarray, variable, additional,
164        inconsistent)'''
165        match [self.links, self.add_name, self.mode]:
166            case [_, _, 'inconsistent']:
167                return 'inconsistent'
168            case [_, _, 'undefined']:
169                return 'metadata'
170            case [None, '', _]:
171                return 'namedarray'
172            case [_, '', _]:
173                return 'variable'
174            case [_, str(), _]:
175                return 'additional'
176            case _:
177                return 'inconsistent'
178
179    @property
180    def full_name(self):
181        '''concatenation of name and additional name'''
182        add_name = '.' + self.add_name if self.add_name else ''
183        return self.name + add_name
184
185    @property
186    def json_name(self):
187        '''concatenation of full_name and ntv_type'''
188        add_ntv_type = ':' + self.ntv_type if self.ntv_type else ''
189        return self.full_name + add_ntv_type
190
191    @staticmethod
192    def read_json(jsn, **kwargs):
193        ''' convert json data into a Xndarray.
194
195        *Parameters*
196
197        - **convert** : boolean (default True) - If True, convert json data with
198        non Numpy ntv_type into data with python type
199        '''
200        option = {'convert': True} | kwargs
201        jso = json.loads(jsn) if isinstance(jsn, str) else jsn
202        value, full_name = Ntv.decode_json(jso)[:2]
203
204        meta = links = nda = None
205        match value:
206            case str(meta) | dict(meta): ...
207            case [list(nda)]: ...
208            case [list(nda), list(links)]: ...
209            case [list(nda), dict(meta)] | [list(nda), str(meta)]: ...
210            case [list(nda), list(links), dict(meta)]: ...
211            case [list(nda), list(links), str(meta)]: ...
212            case _:
213                return None
214        nda = Ndarray.read_json(nda, **option) if nda else None
215        return Xndarray(full_name, links=links, meta=meta, nda=nda)
216
217    def set_ndarray(self, ndarray, nda_uri=True):
218        '''set a new ndarray (nda) and return the result (True, False)
219
220        *Parameters*
221
222        - **ndarray** : string, list, np.ndarray, Ndarray - data to include
223        - **nda_uri** : boolean (default True) - if True, existing shape and
224        ntv_type are not updated (but are created if not existing)'''
225        ndarray = Ndarray(ndarray)
226        if not self.nda is None:
227            return self.nda.update(ndarray, nda_uri=nda_uri)
228        self.nda = ndarray
229        return True
230
231    def to_json(self, **kwargs):
232        ''' convert a Xndarray into json-value.
233
234        *Parameters*
235
236        - **encoded** : Boolean (default False) - json-value if False else json-text
237        - **header** : Boolean (default True) - including xndarray type
238        - **noname** : Boolean (default False) - including data type and name if False
239        - **notype** : Boolean (default False) - including data type if False
240        - **novalue** : Boolean (default False) - including value if False
241        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
242        - **format** : string (default 'full') - representation format of the ndarray,
243        - **extension** : string (default None) - type extension
244        '''
245        option = {'notype': False, 'format': 'full',
246                  'noshape': True, 'header': True, 'encoded': False,
247                  'novalue': False, 'noname': False} | kwargs
248        if not option['format'] in ['full', 'complete']:
249            option['noshape'] = False
250        opt_nda = option | {'header': False}
251        # nda_str = Ndarray.to_json(self.nda,
252        nda_str = self.nda.to_json(**opt_nda) if not self.nda is None else None
253        lis = [nda_str, self.links, self.meta]
254        lis = [val for val in lis if not val is None]
255        return Nutil.json_ntv(None if option['noname'] else self.full_name,
256                              None if option['noname'] else 'xndarray',
257                              lis[0] if lis == [self.meta] else lis,
258                              header=option['header'], encoded=option['encoded'])
259
260    def _to_json(self):
261        '''return dict of attributes'''
262        return {'name': self.name, 'ntv_type': self.ntv_type, 'uri': self.uri,
263                'nda': self.nda, 'meta': self.meta, 'links': self.links}

Representation of a labelled multidimensional Array

Attributes :

  • name : string - name of the Xndarray
  • add_name : string - additional name of the Xndarray
  • nda: Ndarray - ndarray data
  • links: list of string - links to other Xndarray
  • meta : JsonValue - informations

dynamic values (@property)

methods

Xndarray(full_name, nda=None, links=None, meta=None)
49    def __init__(self, full_name, nda=None, links=None,
50                 meta=None):
51        '''Xndarray constructor.
52
53        *Parameters*
54
55        - **full_name**: string (default None) - name with additional name
56        - **nda** : Ndarray (default None) - data
57        - **links**: List of string (default None) - dims or other names of associated Xndarray
58        - **ntv_type**: string (default None) - ntv_type to apply to data
59        - **meta**: dict (default None) - information
60        '''
61        # print('init xnd', full_name, nda.to_json(), links, meta)
62        if isinstance(full_name, Xndarray):
63            self.name = full_name.name
64            self.add_name = full_name.add_name
65            self.nda = full_name.nda
66            self.links = full_name.links
67            self.meta = full_name.meta
68            return
69        self.name, self.add_name = Nutil.split_name(full_name)
70        self.nda = Ndarray(nda) if not nda is None else None
71        self.links = sorted(links) if links else None
72        self.meta = meta if meta else None
73        if self.meta is None and self.nda is None:
74            raise NdarrayError('A Xndarray has to have metadata or Ndarray')

Xndarray constructor.

Parameters

  • full_name: string (default None) - name with additional name
  • nda : Ndarray (default None) - data
  • links: List of string (default None) - dims or other names of associated Xndarray
  • ntv_type: string (default None) - ntv_type to apply to data
  • meta: dict (default None) - information
nda
meta
darray
118    @property
119    def darray(self):
120        '''return the darray of the ndarray'''
121        return self.nda.darray if self.nda is not None else None

return the darray of the ndarray

ndarray
123    @property
124    def ndarray(self):
125        '''return the darray of the ndarray'''
126        return self.nda.ndarray if self.nda is not None else None

return the darray of the ndarray

uri
128    @property
129    def uri(self):
130        '''return the uri of the ndarray'''
131        return self.nda.uri if self.nda is not None else None

return the uri of the ndarray

shape
133    @property
134    def shape(self):
135        '''return the shape of the ndarray'''
136        return self.nda.shape if self.nda is not None else None

return the shape of the ndarray

ntv_type
138    @property
139    def ntv_type(self):
140        '''return the ntv_type of the ndarray'''
141        return self.nda.ntv_type if self.nda is not None else None

return the ntv_type of the ndarray

mode
143    @property
144    def mode(self):
145        '''return the mode of the ndarray'''
146        return self.nda.mode if self.nda is not None else 'undefined'

return the mode of the ndarray

info
148    @property
149    def info(self):
150        ''' infos of the Xndarray'''
151        inf = {'name': self.full_name}
152        inf['length'] = len(self)
153        if self.nda:
154            inf['mode'] = self.mode
155            inf['ntvtype'] = self.ntv_type
156            inf['shape'] = self.shape
157        inf['xtype'] = self.xtype
158        inf['links'] = self.links
159        return {key: val for key, val in inf.items() if val}

infos of the Xndarray

xtype
161    @property
162    def xtype(self):
163        '''nature of the Xndarray (undefined, namedarray, variable, additional,
164        inconsistent)'''
165        match [self.links, self.add_name, self.mode]:
166            case [_, _, 'inconsistent']:
167                return 'inconsistent'
168            case [_, _, 'undefined']:
169                return 'metadata'
170            case [None, '', _]:
171                return 'namedarray'
172            case [_, '', _]:
173                return 'variable'
174            case [_, str(), _]:
175                return 'additional'
176            case _:
177                return 'inconsistent'

nature of the Xndarray (undefined, namedarray, variable, additional, inconsistent)

full_name
179    @property
180    def full_name(self):
181        '''concatenation of name and additional name'''
182        add_name = '.' + self.add_name if self.add_name else ''
183        return self.name + add_name

concatenation of name and additional name

json_name
185    @property
186    def json_name(self):
187        '''concatenation of full_name and ntv_type'''
188        add_ntv_type = ':' + self.ntv_type if self.ntv_type else ''
189        return self.full_name + add_ntv_type

concatenation of full_name and ntv_type

@staticmethod
def read_json(jsn, **kwargs):
191    @staticmethod
192    def read_json(jsn, **kwargs):
193        ''' convert json data into a Xndarray.
194
195        *Parameters*
196
197        - **convert** : boolean (default True) - If True, convert json data with
198        non Numpy ntv_type into data with python type
199        '''
200        option = {'convert': True} | kwargs
201        jso = json.loads(jsn) if isinstance(jsn, str) else jsn
202        value, full_name = Ntv.decode_json(jso)[:2]
203
204        meta = links = nda = None
205        match value:
206            case str(meta) | dict(meta): ...
207            case [list(nda)]: ...
208            case [list(nda), list(links)]: ...
209            case [list(nda), dict(meta)] | [list(nda), str(meta)]: ...
210            case [list(nda), list(links), dict(meta)]: ...
211            case [list(nda), list(links), str(meta)]: ...
212            case _:
213                return None
214        nda = Ndarray.read_json(nda, **option) if nda else None
215        return Xndarray(full_name, links=links, meta=meta, nda=nda)

convert json data into a Xndarray.

Parameters

  • convert : boolean (default True) - If True, convert json data with non Numpy ntv_type into data with python type
def set_ndarray(self, ndarray, nda_uri=True):
217    def set_ndarray(self, ndarray, nda_uri=True):
218        '''set a new ndarray (nda) and return the result (True, False)
219
220        *Parameters*
221
222        - **ndarray** : string, list, np.ndarray, Ndarray - data to include
223        - **nda_uri** : boolean (default True) - if True, existing shape and
224        ntv_type are not updated (but are created if not existing)'''
225        ndarray = Ndarray(ndarray)
226        if not self.nda is None:
227            return self.nda.update(ndarray, nda_uri=nda_uri)
228        self.nda = ndarray
229        return True

set a new ndarray (nda) and return the result (True, False)

Parameters

  • ndarray : string, list, np.ndarray, Ndarray - data to include
  • nda_uri : boolean (default True) - if True, existing shape and ntv_type are not updated (but are created if not existing)
def to_json(self, **kwargs):
231    def to_json(self, **kwargs):
232        ''' convert a Xndarray into json-value.
233
234        *Parameters*
235
236        - **encoded** : Boolean (default False) - json-value if False else json-text
237        - **header** : Boolean (default True) - including xndarray type
238        - **noname** : Boolean (default False) - including data type and name if False
239        - **notype** : Boolean (default False) - including data type if False
240        - **novalue** : Boolean (default False) - including value if False
241        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
242        - **format** : string (default 'full') - representation format of the ndarray,
243        - **extension** : string (default None) - type extension
244        '''
245        option = {'notype': False, 'format': 'full',
246                  'noshape': True, 'header': True, 'encoded': False,
247                  'novalue': False, 'noname': False} | kwargs
248        if not option['format'] in ['full', 'complete']:
249            option['noshape'] = False
250        opt_nda = option | {'header': False}
251        # nda_str = Ndarray.to_json(self.nda,
252        nda_str = self.nda.to_json(**opt_nda) if not self.nda is None else None
253        lis = [nda_str, self.links, self.meta]
254        lis = [val for val in lis if not val is None]
255        return Nutil.json_ntv(None if option['noname'] else self.full_name,
256                              None if option['noname'] else 'xndarray',
257                              lis[0] if lis == [self.meta] else lis,
258                              header=option['header'], encoded=option['encoded'])

convert a Xndarray into json-value.

Parameters

  • encoded : Boolean (default False) - json-value if False else json-text
  • header : Boolean (default True) - including xndarray type
  • noname : Boolean (default False) - including data type and name if False
  • notype : Boolean (default False) - including data type if False
  • novalue : Boolean (default False) - including value if False
  • noshape : Boolean (default True) - if True, without shape if dim < 1
  • format : string (default 'full') - representation format of the ndarray,
  • extension : string (default None) - type extension