Python numpy.fix() Examples
The following are 30
code examples of numpy.fix().
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
, or try the search function
.
Example #1
Source File: test_ufunclike.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_scalar(self): x = np.inf actual = np.isposinf(x) expected = np.True_ assert_equal(actual, expected) assert_equal(type(actual), type(expected)) x = -3.4 actual = np.fix(x) expected = np.float64(-3.0) assert_equal(actual, expected) assert_equal(type(actual), type(expected)) out = np.array(0.0) actual = np.fix(x, out=out) assert_(actual is out)
Example #2
Source File: ext_dmdt.py From feets with MIT License | 6 votes |
def fit(self, magnitude, time, dt_bins, dm_bins): def delta_calc(idx): t0 = time[idx] m0 = magnitude[idx] deltat = time[idx + 1 :] - t0 deltam = magnitude[idx + 1 :] - m0 deltat[np.where(deltat < 0)] *= -1 deltam[np.where(deltat < 0)] *= -1 return np.column_stack((deltat, deltam)) lc_len = len(time) n_vals = int(0.5 * lc_len * (lc_len - 1)) deltas = np.vstack(tuple(delta_calc(idx) for idx in range(lc_len - 1))) deltat = deltas[:, 0] deltam = deltas[:, 1] bins = [dt_bins, dm_bins] counts = np.histogram2d(deltat, deltam, bins=bins, normed=False)[0] result = np.fix(255.0 * counts / n_vals + 0.999).astype(int) return {"DMDT": result}
Example #3
Source File: test_ufunclike.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_scalar(self): x = np.inf actual = np.isposinf(x) expected = np.True_ assert_equal(actual, expected) assert_equal(type(actual), type(expected)) x = -3.4 actual = np.fix(x) expected = np.float64(-3.0) assert_equal(actual, expected) assert_equal(type(actual), type(expected)) out = np.array(0.0) actual = np.fix(x, out=out) assert_(actual is out)
Example #4
Source File: mtcnn.py From tensorrt_demos with MIT License | 6 votes |
def convert_to_1x1(boxes): """Convert detection boxes to 1:1 sizes # Arguments boxes: numpy array, shape (n,5), dtype=float32 # Returns boxes_1x1 """ boxes_1x1 = boxes.copy() hh = boxes[:, 3] - boxes[:, 1] + 1. ww = boxes[:, 2] - boxes[:, 0] + 1. mm = np.maximum(hh, ww) boxes_1x1[:, 0] = boxes[:, 0] + ww * 0.5 - mm * 0.5 boxes_1x1[:, 1] = boxes[:, 1] + hh * 0.5 - mm * 0.5 boxes_1x1[:, 2] = boxes_1x1[:, 0] + mm - 1. boxes_1x1[:, 3] = boxes_1x1[:, 1] + mm - 1. boxes_1x1[:, 0:4] = np.fix(boxes_1x1[:, 0:4]) return boxes_1x1
Example #5
Source File: util.py From wradlib with MIT License | 6 votes |
def filter_window_cartesian(img, wsize, fun, scale, **kwargs): """Apply a filter of square window size `fsize` on a given \ cartesian image `img`. Parameters ---------- img : :class:`numpy:numpy.ndarray` 2d array of values to which the filter is to be applied wsize : float Half size of the window centred on the pixel [m] fun : string name of the 2d filter from :mod:`scipy:scipy.ndimage` scale : tuple of 2 floats x and y scale of the cartesian grid [m] Returns ------- output : :class:`numpy:numpy.ndarray` Array with the same shape as `img`, containing the filter's results. """ fun = getattr(ndimage.filters, "%s_filter" % fun) size = np.fix(wsize / scale + 0.5).astype(int) data_filtered = fun(img, size, **kwargs) return data_filtered
Example #6
Source File: test_ufunclike.py From recruit with Apache License 2.0 | 6 votes |
def test_scalar(self): x = np.inf actual = np.isposinf(x) expected = np.True_ assert_equal(actual, expected) assert_equal(type(actual), type(expected)) x = -3.4 actual = np.fix(x) expected = np.float64(-3.0) assert_equal(actual, expected) assert_equal(type(actual), type(expected)) out = np.array(0.0) actual = np.fix(x, out=out) assert_(actual is out)
Example #7
Source File: test_ufunclike.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_scalar(self): x = np.inf actual = np.isposinf(x) expected = np.True_ assert_equal(actual, expected) assert_equal(type(actual), type(expected)) x = -3.4 actual = np.fix(x) expected = np.float64(-3.0) assert_equal(actual, expected) assert_equal(type(actual), type(expected)) out = np.array(0.0) actual = np.fix(x, out=out) assert_(actual is out)
Example #8
Source File: test_ufunclike.py From pySINDy with MIT License | 6 votes |
def test_scalar(self): x = np.inf actual = np.isposinf(x) expected = np.True_ assert_equal(actual, expected) assert_equal(type(actual), type(expected)) x = -3.4 actual = np.fix(x) expected = np.float64(-3.0) assert_equal(actual, expected) assert_equal(type(actual), type(expected)) out = np.array(0.0) actual = np.fix(x, out=out) assert_(actual is out)
Example #9
Source File: pYAAPT.py From AMFM_decompy with MIT License | 6 votes |
def fix(self): if self.PITCH_HALF > 0: nz_pitch = self.samp_values[self.samp_values > 0] idx = self.samp_values < (np.mean(nz_pitch)-self.PITCH_HALF_SENS * np.std(nz_pitch)) if self.PITCH_HALF == 1: self.samp_values[idx] = 0 elif self.PITCH_HALF == 2: self.samp_values[idx] = 2*self.samp_values[idx] if self.PITCH_DOUBLE > 0: nz_pitch = self.samp_values[self.samp_values > 0] idx = self.samp_values > (np.mean(nz_pitch)+self.PITCH_DOUBLE_SENS * np.std(nz_pitch)) if self.PITCH_DOUBLE == 1: self.samp_values[idx] = 0 elif self.PITCH_DOUBLE == 2: self.samp_values[idx] = 0.5*self.samp_values[idx]
Example #10
Source File: test_ufunclike.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_fix_with_subclass(self): class MyArray(nx.ndarray): def __new__(cls, data, metadata=None): res = nx.array(data, copy=True).view(cls) res.metadata = metadata return res def __array_wrap__(self, obj, context=None): obj.metadata = self.metadata return obj a = nx.array([1.1, -1.1]) m = MyArray(a, metadata='foo') f = ufl.fix(m) assert_array_equal(f, nx.array([1, -1])) assert_(isinstance(f, MyArray)) assert_equal(f.metadata, 'foo') # check 0d arrays don't decay to scalars m0d = m[0,...] m0d.metadata = 'bar' f0d = ufl.fix(m0d) assert_(isinstance(f0d, MyArray)) assert_equal(f0d.metadata, 'bar')
Example #11
Source File: test_ufunclike.py From vnpy_crypto with MIT License | 6 votes |
def test_fix_with_subclass(self): class MyArray(nx.ndarray): def __new__(cls, data, metadata=None): res = nx.array(data, copy=True).view(cls) res.metadata = metadata return res def __array_wrap__(self, obj, context=None): obj.metadata = self.metadata return obj a = nx.array([1.1, -1.1]) m = MyArray(a, metadata='foo') f = ufl.fix(m) assert_array_equal(f, nx.array([1, -1])) assert_(isinstance(f, MyArray)) assert_equal(f.metadata, 'foo') # check 0d arrays don't decay to scalars m0d = m[0,...] m0d.metadata = 'bar' f0d = ufl.fix(m0d) assert_(isinstance(f0d, MyArray)) assert_equal(f0d.metadata, 'bar')
Example #12
Source File: test_ufunclike.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_scalar(self): x = np.inf actual = np.isposinf(x) expected = np.True_ assert_equal(actual, expected) assert_equal(type(actual), type(expected)) x = -3.4 actual = np.fix(x) expected = np.float64(-3.0) assert_equal(actual, expected) assert_equal(type(actual), type(expected)) out = np.array(0.0) actual = np.fix(x, out=out) assert_(actual is out)
Example #13
Source File: test_ufunclike.py From vnpy_crypto with MIT License | 6 votes |
def test_scalar(self): x = np.inf actual = np.isposinf(x) expected = np.True_ assert_equal(actual, expected) assert_equal(type(actual), type(expected)) x = -3.4 actual = np.fix(x) expected = np.float64(-3.0) assert_equal(actual, expected) assert_equal(type(actual), type(expected)) out = np.array(0.0) actual = np.fix(x, out=out) assert_(actual is out)
Example #14
Source File: mtcnn.py From tensorrt_demos with MIT License | 6 votes |
def detect(self, img, minsize=40): """detect() This function handles rescaling of the input image if it's larger than 1280x720. """ if img is None: raise ValueError img_h, img_w, _ = img.shape scale = min(720. / img_h, 1280. / img_w) if scale < 1.0: new_h = int(np.ceil(img_h * scale)) new_w = int(np.ceil(img_w * scale)) img = cv2.resize(img, (new_w, new_h)) minsize = max(int(np.ceil(minsize * scale)), 40) dets, landmarks = self._detect_1280x720(img, minsize) if scale < 1.0: dets[:, :-1] = np.fix(dets[:, :-1] / scale) landmarks = np.fix(landmarks / scale) return dets, landmarks
Example #15
Source File: tools.py From MTCNN-Tensorflow with MIT License | 5 votes |
def generateBoundingBox(imap, reg, scale, t): stride = 2 cellsize = 12 imap = np.transpose(imap) dx1 = np.transpose(reg[:, :, 0]) dy1 = np.transpose(reg[:, :, 1]) dx2 = np.transpose(reg[:, :, 2]) dy2 = np.transpose(reg[:, :, 3]) y, x = np.where(imap >= t) if y.shape[0] == 1: dx1 = np.flipud(dx1) dy1 = np.flipud(dy1) dx2 = np.flipud(dx2) dy2 = np.flipud(dy2) score = imap[(y, x)] reg = np.transpose(np.vstack([dx1[(y, x)], dy1[(y, x)], dx2[(y, x)], dy2[(y, x)]])) if reg.size == 0: reg = np.empty((0, 3)) bb = np.transpose(np.vstack([y, x])) q1 = np.fix((stride * bb + 1) / scale) q2 = np.fix((stride * bb + cellsize - 1 + 1) / scale) boundingbox = np.hstack([q1, q2, np.expand_dims(score, 1), reg]) return boundingbox, reg
Example #16
Source File: mtcnn.py From tensorrt_demos with MIT License | 5 votes |
def clip_dets(dets, img_w, img_h): """Round and clip detection (x1, y1, ...) values. Note we exclude the last value of 'dets' in computation since it is 'conf'. """ dets[:, 0:-1] = np.fix(dets[:, 0:-1]) evens = np.arange(0, dets.shape[1]-1, 2) odds = np.arange(1, dets.shape[1]-1, 2) dets[:, evens] = np.clip(dets[:, evens], 0., float(img_w-1)) dets[:, odds] = np.clip(dets[:, odds], 0., float(img_h-1)) return dets
Example #17
Source File: mtcnn.py From faceswap with GNU General Public License v3.0 | 5 votes |
def detect_face_12net(cls_prob, roi, out_side, scale, width, height, threshold): # pylint: disable=too-many-locals, too-many-arguments """ Detect face position and calibrate bounding box on 12net feature map(matrix version) Input: cls_prob : softmax feature map for face classify roi : feature map for regression out_side : feature map's largest size scale : current input image scale in multi-scales width : image's origin width height : image's origin height threshold: 0.6 can have 99% recall rate """ in_side = 2*out_side+11 stride = 0 if out_side != 1: stride = float(in_side-12)/(out_side-1) (var_x, var_y) = np.where(cls_prob >= threshold) boundingbox = np.array([var_x, var_y]).T bb1 = np.fix((stride * (boundingbox) + 0) * scale) bb2 = np.fix((stride * (boundingbox) + 11) * scale) boundingbox = np.concatenate((bb1, bb2), axis=1) dx_1 = roi[0][var_x, var_y] dx_2 = roi[1][var_x, var_y] dx3 = roi[2][var_x, var_y] dx4 = roi[3][var_x, var_y] score = np.array([cls_prob[var_x, var_y]]).T offset = np.array([dx_1, dx_2, dx3, dx4]).T boundingbox = boundingbox + offset*12.0*scale rectangles = np.concatenate((boundingbox, score), axis=1) rectangles = rect2square(rectangles) pick = [] for rect in rectangles: x_1 = int(max(0, rect[0])) y_1 = int(max(0, rect[1])) x_2 = int(min(width, rect[2])) y_2 = int(min(height, rect[3])) sc_ = rect[4] if x_2 > x_1 and y_2 > y_1: pick.append([x_1, y_1, x_2, y_2, sc_]) return nms(pick, 0.3, "iou")
Example #18
Source File: detect_face.py From facenet_mtcnn_to_mobile with MIT License | 5 votes |
def generateBoundingBox(imap, reg, scale, t): """Use heatmap to generate bounding boxes""" stride=2 cellsize=12 imap = np.transpose(imap) dx1 = np.transpose(reg[:,:,0]) dy1 = np.transpose(reg[:,:,1]) dx2 = np.transpose(reg[:,:,2]) dy2 = np.transpose(reg[:,:,3]) y, x = np.where(imap >= t) if y.shape[0]==1: dx1 = np.flipud(dx1) dy1 = np.flipud(dy1) dx2 = np.flipud(dx2) dy2 = np.flipud(dy2) score = imap[(y,x)] reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ])) if reg.size==0: reg = np.empty((0,3)) bb = np.transpose(np.vstack([y,x])) q1 = np.fix((stride*bb+1)/scale) q2 = np.fix((stride*bb+cellsize-1+1)/scale) boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg]) return boundingbox, reg # function pick = nms(boxes,threshold,type)
Example #19
Source File: pYAAPT.py From AMFM_decompy with MIT License | 5 votes |
def set_values(self, samp_values, file_size, interp_tech='pchip'): self.samp_values = samp_values self.fix() self.values = self.upsample(self.samp_values, file_size, 0, 0, interp_tech) self.edges = self.edges_finder(self.values) self.interpolate() self.values_interp = self.upsample(self.samp_interp, file_size, self.samp_interp[0], self.samp_interp[-1], interp_tech)
Example #20
Source File: pYAAPT.py From AMFM_decompy with MIT License | 5 votes |
def nlfer(signal, pitch, parameters): #--------------------------------------------------------------- # Set parameters. #--------------------------------------------------------------- N_f0_min = np.around((parameters['f0_min']*2/float(signal.new_fs))*pitch.nfft) N_f0_max = np.around((parameters['f0_max']/float(signal.new_fs))*pitch.nfft) window = hann(pitch.frame_size+2)[1:-1] data = np.zeros((signal.size)) #Needs other array, otherwise stride and data[:] = signal.filtered #windowing will modify signal.filtered #--------------------------------------------------------------- # Main routine. #--------------------------------------------------------------- samples = np.arange(int(np.fix(float(pitch.frame_size)/2)), signal.size-int(np.fix(float(pitch.frame_size)/2)), pitch.frame_jump) data_matrix = np.empty((len(samples), pitch.frame_size)) data_matrix[:, :] = stride_matrix(data, len(samples), pitch.frame_size, pitch.frame_jump) data_matrix *= window specData = np.fft.rfft(data_matrix, pitch.nfft) frame_energy = np.abs(specData[:, int(N_f0_min-1):int(N_f0_max)]).sum(axis=1) pitch.set_energy(frame_energy, parameters['nlfer_thresh1']) pitch.set_frames_pos(samples)
Example #21
Source File: tools_matrix.py From SmooFaceEngine with Apache License 2.0 | 5 votes |
def detect_face_12net(cls_prob,roi,out_side,scale,width,height,threshold): in_side = 2*out_side+11 stride = 0 if out_side != 1: stride = float(in_side-12)/(out_side-1) (x,y) = np.where(cls_prob>=threshold) boundingbox = np.array([x,y]).T bb1 = np.fix((stride * (boundingbox) + 0 ) * scale) bb2 = np.fix((stride * (boundingbox) + 11) * scale) boundingbox = np.concatenate((bb1,bb2),axis = 1) dx1 = roi[0][x,y] dx2 = roi[1][x,y] dx3 = roi[2][x,y] dx4 = roi[3][x,y] score = np.array([cls_prob[x,y]]).T offset = np.array([dx1,dx2,dx3,dx4]).T boundingbox = boundingbox + offset*12.0*scale rectangles = np.concatenate((boundingbox,score),axis=1) rectangles = rect2square(rectangles) pick = [] for i in range(len(rectangles)): x1 = int(max(0 ,rectangles[i][0])) y1 = int(max(0 ,rectangles[i][1])) x2 = int(min(width ,rectangles[i][2])) y2 = int(min(height,rectangles[i][3])) sc = rectangles[i][4] if x2>x1 and y2>y1: pick.append([x1,y1,x2,y2,sc]) return NMS(pick,0.3,'iou')
Example #22
Source File: mtcnn.py From mtcnn with MIT License | 5 votes |
def __generate_bounding_box(imap, reg, scale, t): # use heatmap to generate bounding boxes stride = 2 cellsize = 12 imap = np.transpose(imap) dx1 = np.transpose(reg[:, :, 0]) dy1 = np.transpose(reg[:, :, 1]) dx2 = np.transpose(reg[:, :, 2]) dy2 = np.transpose(reg[:, :, 3]) y, x = np.where(imap >= t) if y.shape[0] == 1: dx1 = np.flipud(dx1) dy1 = np.flipud(dy1) dx2 = np.flipud(dx2) dy2 = np.flipud(dy2) score = imap[(y, x)] reg = np.transpose(np.vstack([dx1[(y, x)], dy1[(y, x)], dx2[(y, x)], dy2[(y, x)]])) if reg.size == 0: reg = np.empty(shape=(0, 3)) bb = np.transpose(np.vstack([y, x])) q1 = np.fix((stride * bb + 1) / scale) q2 = np.fix((stride * bb + cellsize) / scale) boundingbox = np.hstack([q1, q2, np.expand_dims(score, 1), reg]) return boundingbox, reg
Example #23
Source File: test_ufunclike.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_deprecated(self): # NumPy 1.13.0, 2017-04-26 assert_warns(DeprecationWarning, ufl.fix, [1, 2], y=nx.empty(2)) assert_warns(DeprecationWarning, ufl.isposinf, [1, 2], y=nx.empty(2)) assert_warns(DeprecationWarning, ufl.isneginf, [1, 2], y=nx.empty(2))
Example #24
Source File: test_ufunclike.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_fix(self): a = nx.array([[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]]) out = nx.zeros(a.shape, float) tgt = nx.array([[1., 1., 1., 1.], [-1., -1., -1., -1.]]) res = ufl.fix(a) assert_equal(res, tgt) res = ufl.fix(a, out) assert_equal(res, tgt) assert_equal(out, tgt) assert_equal(ufl.fix(3.14), 3)
Example #25
Source File: entropy.py From pyEntropy with Apache License 2.0 | 5 votes |
def util_granulate_time_series(time_series, scale): """Extract coarse-grained time series Args: time_series: Time series scale: Scale factor Returns: Vector of coarse-grained time series with given scale factor """ n = len(time_series) b = int(np.fix(n / scale)) temp = np.reshape(time_series[0:b*scale], (b, scale)) cts = np.mean(temp, axis = 1) return cts
Example #26
Source File: detect_face.py From 1.FaceRecognition with MIT License | 5 votes |
def generateBoundingBox(imap, reg, scale, t): # use heatmap to generate bounding boxes stride=2 cellsize=12 imap = np.transpose(imap) dx1 = np.transpose(reg[:,:,0]) dy1 = np.transpose(reg[:,:,1]) dx2 = np.transpose(reg[:,:,2]) dy2 = np.transpose(reg[:,:,3]) y, x = np.where(imap >= t) if y.shape[0]==1: dx1 = np.flipud(dx1) dy1 = np.flipud(dy1) dx2 = np.flipud(dx2) dy2 = np.flipud(dy2) score = imap[(y,x)] reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ])) if reg.size==0: reg = np.empty((0,3)) bb = np.transpose(np.vstack([y,x])) q1 = np.fix((stride*bb+1)/scale) q2 = np.fix((stride*bb+cellsize-1+1)/scale) boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg]) return boundingbox, reg # function pick = nms(boxes,threshold,type)
Example #27
Source File: network.py From celeb-detection-oss with Mozilla Public License 2.0 | 5 votes |
def generateBoundingBox(imap, reg, scale, t): # use heatmap to generate bounding boxes stride = 2 cellsize = 12 imap = np.transpose(imap) dx1 = np.transpose(reg[:, :, 0]) dy1 = np.transpose(reg[:, :, 1]) dx2 = np.transpose(reg[:, :, 2]) dy2 = np.transpose(reg[:, :, 3]) y, x = np.where(imap >= t) if y.shape[0] == 1: dx1 = np.flipud(dx1) dy1 = np.flipud(dy1) dx2 = np.flipud(dx2) dy2 = np.flipud(dy2) score = imap[(y, x)] reg = np.transpose(np.vstack([dx1[(y, x)], dy1[(y, x)], dx2[(y, x)], dy2[(y, x)]])) if reg.size == 0: reg = np.empty((0, 3)) bb = np.transpose(np.vstack([y, x])) q1 = np.fix((stride*bb+1)/scale) q2 = np.fix((stride*bb+cellsize-1+1)/scale) boundingbox = np.hstack([q1, q2, np.expand_dims(score, 1), reg]) return boundingbox, reg # function pick = nms(boxes, threshold, type)
Example #28
Source File: test_ufunclike.py From pySINDy with MIT License | 5 votes |
def test_deprecated(self): # NumPy 1.13.0, 2017-04-26 assert_warns(DeprecationWarning, ufl.fix, [1, 2], y=nx.empty(2)) assert_warns(DeprecationWarning, ufl.isposinf, [1, 2], y=nx.empty(2)) assert_warns(DeprecationWarning, ufl.isneginf, [1, 2], y=nx.empty(2))
Example #29
Source File: test_ufunclike.py From pySINDy with MIT License | 5 votes |
def test_fix_with_subclass(self): class MyArray(nx.ndarray): def __new__(cls, data, metadata=None): res = nx.array(data, copy=True).view(cls) res.metadata = metadata return res def __array_wrap__(self, obj, context=None): obj.metadata = self.metadata return obj def __array_finalize__(self, obj): self.metadata = getattr(obj, 'metadata', None) return self a = nx.array([1.1, -1.1]) m = MyArray(a, metadata='foo') f = ufl.fix(m) assert_array_equal(f, nx.array([1, -1])) assert_(isinstance(f, MyArray)) assert_equal(f.metadata, 'foo') # check 0d arrays don't decay to scalars m0d = m[0,...] m0d.metadata = 'bar' f0d = ufl.fix(m0d) assert_(isinstance(f0d, MyArray)) assert_equal(f0d.metadata, 'bar')
Example #30
Source File: test_ufunclike.py From pySINDy with MIT License | 5 votes |
def test_fix(self): a = nx.array([[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]]) out = nx.zeros(a.shape, float) tgt = nx.array([[1., 1., 1., 1.], [-1., -1., -1., -1.]]) res = ufl.fix(a) assert_equal(res, tgt) res = ufl.fix(a, out) assert_equal(res, tgt) assert_equal(out, tgt) assert_equal(ufl.fix(3.14), 3)