Python numpy.core.numeric.newaxis() Examples
The following are 22
code examples of numpy.core.numeric.newaxis().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy.core.numeric
, or try the search function
.
Example #1
Source File: utils.py From ProxImaL with MIT License | 6 votes |
def _stack(arrays, axis=0): arrays = [np.asanyarray(arr) for arr in arrays] if not arrays: raise ValueError('need at least one array to stack') shapes = set(arr.shape for arr in arrays) if len(shapes) != 1: raise ValueError('all input arrays must have the same shape') result_ndim = arrays[0].ndim + 1 if not -result_ndim <= axis < result_ndim: msg = 'axis {0} out of bounds [-{1}, {1})'.format(axis, result_ndim) raise np.IndexError(msg) if axis < 0: axis += result_ndim sl = (slice(None),) * axis + (numeric.newaxis,) expanded_arrays = [arr[sl] for arr in arrays] return numeric.concatenate(expanded_arrays, axis=axis)
Example #2
Source File: utils.py From ProxImaL with MIT License | 5 votes |
def estimate_std(z, method='daub_reflect'): # Estimates noise standard deviation assuming additive gaussian noise # Check method if (method not in NoiseEstMethod.values()) and (method in NoiseEstMethod.keys()): method = NoiseEstMethod[method] else: raise Exception("Invalid noise estimation method.") # Check shape if len(z.shape) == 2: z = z[..., np.newaxis] elif len(z.shape) != 3: raise Exception("Supports only up to 3D images.") # Run on multichannel image channels = z.shape[2] dev = np.zeros(channels) # Iterate over channels for ch in range(channels): # Daubechies denoising method if method == NoiseEstMethod['daub_reflect'] or method == NoiseEstMethod['daub_replicate']: daub6kern = np.array([0.03522629188571, 0.08544127388203, -0.13501102001025, -0.45987750211849, 0.80689150931109, -0.33267055295008], dtype=np.float32, order='F') if method == NoiseEstMethod['daub_reflect']: wav_det = cv2.sepFilter2D(z, -1, daub6kern, daub6kern, borderType=cv2.BORDER_REFLECT_101) else: wav_det = cv2.sepFilter2D(z, -1, daub6kern, daub6kern, borderType=cv2.BORDER_REPLICATE) dev[ch] = np.median(np.absolute(wav_det)) / 0.6745 # Return standard deviation return dev
Example #3
Source File: index_tricks.py From keras-lambda with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #4
Source File: index_tricks.py From recruit with Apache License 2.0 | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][tuple(slobj)] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #5
Source File: index_tricks.py From twitter-stock-recommendation with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][tuple(slobj)] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #6
Source File: index_tricks.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][tuple(slobj)] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #7
Source File: index_tricks.py From Carnets with BSD 3-Clause "New" or "Revised" License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][tuple(slobj)] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #8
Source File: index_tricks.py From coffeegrindsize with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][tuple(slobj)] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #9
Source File: index_tricks.py From elasticintel with GNU General Public License v3.0 | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #10
Source File: index_tricks.py From Splunking-Crime with GNU Affero General Public License v3.0 | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #11
Source File: index_tricks.py From ImageFusion with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #12
Source File: index_tricks.py From mxnet-lambda with Apache License 2.0 | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #13
Source File: index_tricks.py From pySINDy with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][tuple(slobj)] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #14
Source File: index_tricks.py From Fluid-Designer with GNU General Public License v3.0 | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #15
Source File: index_tricks.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][tuple(slobj)] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #16
Source File: index_tricks.py From GraphicDesignPatternByPython with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][tuple(slobj)] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #17
Source File: index_tricks.py From Mastering-Elasticsearch-7.0 with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][tuple(slobj)] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #18
Source File: index_tricks.py From Computable with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start=0 if step is None: step=1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append(int(math.ceil((key[k].stop - start)/(step*1.0)))) if isinstance(step, float) or \ isinstance(start, float) or \ isinstance(key[k].stop, float): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start=0 if step is None: step=1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop+step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #19
Source File: index_tricks.py From vnpy_crypto with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #20
Source File: index_tricks.py From auto-alt-text-lambda-api with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #21
Source File: index_tricks.py From lambda-packs with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)
Example #22
Source File: index_tricks.py From lambda-packs with MIT License | 4 votes |
def __getitem__(self, key): try: size = [] typ = int for k in range(len(key)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) if (isinstance(step, float) or isinstance(start, float) or isinstance(key[k].stop, float)): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) for _x, _t in zip(size, (typ,)*len(size))] else: nn = _nx.indices(size, typ) for k in range(len(size)): step = key[k].step start = key[k].start if start is None: start = 0 if step is None: step = 1 if isinstance(step, complex): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) nn[k] = (nn[k]*step+start) if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): slobj[k] = slice(None, None) nn[k] = nn[k][tuple(slobj)] slobj[k] = _nx.newaxis return nn except (IndexError, TypeError): step = key.step stop = key.stop start = key.start if start is None: start = 0 if isinstance(step, complex): step = abs(step) length = int(step) if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop + step return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step)