本文整理汇总了Python中numpy.zeros方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.zeros方法的具体用法?Python numpy.zeros怎么用?Python numpy.zeros使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块numpy的用法示例。

在下文中一共展示了numpy.zeros方法的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: wordbag2mat

​点赞 7

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def wordbag2mat(self, wordbag): #testing

if self.model==None:

raise Exception("no model")

matrix=np.empty((len(wordbag),self.len_vector))

#如果词典中不存在该词,抛出异常,但暂时还没有自定义词典的办法,所以暂时不那么严格

#try:

# for i in range(len(wordbag)):

# matrix[i,:]=self.model[wordbag[i]]

#except:

# raise Exception("'%s' can not be found in dictionary." % wordbag[i])

#如果词典中不存在该词,则push进一列零向量

for i in range(len(wordbag)):

try:

matrix[i,:]=self.model.wv.__getitem__(wordbag[i])#[wordbag[i]]

except:

matrix[i,:]=np.zeros((1,self.len_vector))

return matrix

################################ problem #####################################

开发者ID:Coldog2333,项目名称:Financial-NLP,代码行数:20,

示例2: similarity_label

​点赞 7

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def similarity_label(self, words, normalization=True):

"""

you can calculate more than one word at the same time.

"""

if self.model==None:

raise Exception('no model.')

if isinstance(words, string_types):

words=[words]

vectors=np.transpose(self.model.wv.__getitem__(words))

if normalization:

unit_vector=unitvec(vectors,ax=0) # 这样写比原来那样速度提升一倍

#unit_vector=np.zeros((len(vectors),len(words)))

#for i in range(len(words)):

# unit_vector[:,i]=matutils.unitvec(vectors[:,i])

dists=np.dot(self.Label_vec_u, unit_vector)

else:

dists=np.dot(self.Label_vec, vectors)

return dists

开发者ID:Coldog2333,项目名称:Financial-NLP,代码行数:20,

示例3: get_a_datum

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def get_a_datum(self):

if self._compressed:

datum = extract_sample(

self._data[self._cur], self._mean, self._resize)

else:

datum = self._data[self._cur]

# start parsing labels

label_elems = parse_label(self._label[self._cur])

label = np.zeros(self._label_dim)

if not self._multilabel:

label[0] = label_elems[0]

else:

for i in label_elems:

label[i] = 1

self._cur = (self._cur + 1) % self._sample_count

return datum, label

开发者ID:liuxianming,项目名称:Caffe-Python-Data-Layer,代码行数:18,

示例4: load_keypoints

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def load_keypoints(image_filepath, image_height, image_width):

"""Load facial keypoints of one image."""

fp_keypoints = "%s.cat" % (image_filepath,)

if not os.path.isfile(fp_keypoints):

raise Exception("Could not find keypoint coordinates for image '%s'." \

% (image_filepath,))

else:

coords_raw = open(fp_keypoints, "r").readlines()[0].strip().split(" ")

coords_raw = [abs(int(coord)) for coord in coords_raw]

keypoints = []

#keypoints_arr = np.zeros((9*2,), dtype=np.int32)

for i in range(1, len(coords_raw), 2): # first element is the number of coords

x = np.clip(coords_raw[i], 0, image_width-1)

y = np.clip(coords_raw[i+1], 0, image_height-1)

keypoints.append((x, y))

return keypoints

开发者ID:aleju,项目名称:cat-bbs,代码行数:19,

示例5: wer

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def wer(self, r, h):

# initialisation

d = np.zeros((len(r)+1)*(len(h)+1), dtype=np.uint8)

d = d.reshape((len(r)+1, len(h)+1))

for i in range(len(r)+1):

for j in range(len(h)+1):

if i == 0:

d[0][j] = j

elif j == 0:

d[i][0] = i

# computation

for i in range(1, len(r)+1):

for j in range(1, len(h)+1):

if r[i-1] == h[j-1]:

d[i][j] = d[i-1][j-1]

else:

substitution = d[i-1][j-1] + 1

insertion = d[i][j-1] + 1

deletion = d[i-1][j] + 1

d[i][j] = min(substitution, insertion, deletion)

return d[len(r)][len(h)]

开发者ID:sailordiary,项目名称:LipNet-PyTorch,代码行数:25,

示例6: compliance_function_fdiff

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def compliance_function_fdiff(self, x, dc):

obj = self.compliance_function(x, dc)

x0 = x.copy()

dc0 = dc.copy()

dcf = np.zeros(dc.shape)

for i, v in enumerate(x):

x = x0.copy()

x[i] += 1e-6

o1 = self.compliance_function(x, dc)

x[i] = x0[i] - 1e-6

o2 = self.compliance_function(x, dc)

dcf[i] = (o1 - o2) / (2e-6)

print("finite differences: {:g}".format(np.linalg.norm(dcf - dc0)))

dc[:] = dc0

return obj

开发者ID:zfergus,项目名称:fenics-topopt,代码行数:19,

示例7: calculate_fdiff_stress

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def calculate_fdiff_stress(self, x, u, nu, side=1, dx=1e-6):

"""

Calculate the derivative of the Von Mises stress using finite

differences given the densities x, displacements u, and young modulus

nu. Optionally, provide the side length (default: 1) and delta x

(default: 1e-6).

"""

ds = self.calculate_diff_stress(x, u, nu, side)

dsf = numpy.zeros(x.shape)

x = numpy.expand_dims(x, -1)

for i in range(x.shape[0]):

delta = scipy.sparse.coo_matrix(([dx], [[i], [0]]), shape=x.shape)

s1 = self.calculate_stress((x + delta.A).squeeze(), u, nu, side)

s2 = self.calculate_stress((x - delta.A).squeeze(), u, nu, side)

dsf[i] = ((s1 - s2) / (2. * dx))[i]

print("finite differences: {:g}".format(numpy.linalg.norm(dsf - ds)))

return dsf

开发者ID:zfergus,项目名称:fenics-topopt,代码行数:19,

示例8: test_add_uniform_time_weights

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def test_add_uniform_time_weights():

time = np.array([15, 46, 74])

data = np.zeros((3))

ds = xr.DataArray(data,

coords=[time],

dims=[TIME_STR],

name='a').to_dataset()

units_str = 'days since 2000-01-01 00:00:00'

cal_str = 'noleap'

ds[TIME_STR].attrs['units'] = units_str

ds[TIME_STR].attrs['calendar'] = cal_str

with pytest.raises(KeyError):

ds[TIME_WEIGHTS_STR]

ds = add_uniform_time_weights(ds)

time_weights_expected = xr.DataArray(

[1, 1, 1], coords=ds[TIME_STR].coords, name=TIME_WEIGHTS_STR)

time_weights_expected.attrs['units'] = 'days'

assert ds[TIME_WEIGHTS_STR].identical(time_weights_expected)

开发者ID:spencerahill,项目名称:aospy,代码行数:22,

示例9: ds_time_encoded_cf

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def ds_time_encoded_cf():

time_bounds = np.array([[0, 31], [31, 59], [59, 90]])

bounds = np.array([0, 1])

time = np.array([15, 46, 74])

data = np.zeros((3))

ds = xr.DataArray(data,

coords=[time],

dims=[TIME_STR],

name='a').to_dataset()

ds[TIME_BOUNDS_STR] = xr.DataArray(time_bounds,

coords=[time, bounds],

dims=[TIME_STR, BOUNDS_STR],

name=TIME_BOUNDS_STR)

units_str = 'days since 2000-01-01 00:00:00'

cal_str = 'noleap'

ds[TIME_STR].attrs['units'] = units_str

ds[TIME_STR].attrs['calendar'] = cal_str

return ds

开发者ID:spencerahill,项目名称:aospy,代码行数:20,

示例10: ds_with_time_bounds

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def ds_with_time_bounds(alt_lat_str, var_name):

time_bounds = np.array([[0, 31], [31, 59], [59, 90]])

bounds = np.array([0, 1])

time = np.array([15, 46, 74])

data = np.zeros((3, 1, 1))

lat = [0]

lon = [0]

ds = xr.DataArray(data,

coords=[time, lat, lon],

dims=[TIME_STR, alt_lat_str, LON_STR],

name=var_name).to_dataset()

ds[TIME_BOUNDS_STR] = xr.DataArray(time_bounds,

coords=[time, bounds],

dims=[TIME_STR, BOUNDS_STR],

name=TIME_BOUNDS_STR)

units_str = 'days since 2000-01-01 00:00:00'

ds[TIME_STR].attrs['units'] = units_str

ds[TIME_BOUNDS_STR].attrs['units'] = units_str

return ds

开发者ID:spencerahill,项目名称:aospy,代码行数:21,

示例11: test_sel_var

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def test_sel_var():

time = np.array([0, 31, 59]) + 15

data = np.zeros((3))

ds = xr.DataArray(data,

coords=[time],

dims=[TIME_STR],

name=convection_rain.name).to_dataset()

condensation_rain_alt_name, = condensation_rain.alt_names

ds[condensation_rain_alt_name] = xr.DataArray(data, coords=[ds.time])

result = _sel_var(ds, convection_rain)

assert result.name == convection_rain.name

result = _sel_var(ds, condensation_rain)

assert result.name == condensation_rain.name

with pytest.raises(LookupError):

_sel_var(ds, precip)

开发者ID:spencerahill,项目名称:aospy,代码行数:19,

示例12: build

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def build(self):

#{{{

import numpy as np;

self.W = shared((self.input_dim, 4 * self.output_dim),

name='{}_W'.format(self.name))

self.U = shared((self.output_dim, 4 * self.output_dim),

name='{}_U'.format(self.name))

self.b = K.variable(np.hstack((np.zeros(self.output_dim),

K.get_value(self.forget_bias_init(

(self.output_dim,))),

np.zeros(self.output_dim),

np.zeros(self.output_dim))),

name='{}_b'.format(self.name))

#self.c_0 = shared((self.output_dim,), name='{}_c_0'.format(self.name) )

#self.h_0 = shared((self.output_dim,), name='{}_h_0'.format(self.name) )

self.c_0=np.zeros(self.output_dim).astype(theano.config.floatX);

self.h_0=np.zeros(self.output_dim).astype(theano.config.floatX);

self.params=[self.W,self.U,

self.b,

# self.c_0,self.h_0

];

#}}}

开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:25,代码来源:nn.py

示例13: ctc_update_log_p

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def ctc_update_log_p(skip_idxs, zeros, active, log_p_curr, log_p_prev):

active_skip_idxs = skip_idxs[(skip_idxs < active).nonzero()]

active_next = T.cast(T.minimum(

T.maximum(

active + 1,

T.max(T.concatenate([active_skip_idxs, [-1]])) + 2 + 1

), log_p_curr.shape[0]), 'int32')

common_factor = T.max(log_p_prev[:active])

p_prev = T.exp(log_p_prev[:active] - common_factor)

_p_prev = zeros[:active_next]

# copy over

_p_prev = T.set_subtensor(_p_prev[:active], p_prev)

# previous transitions

_p_prev = T.inc_subtensor(_p_prev[1:], _p_prev[:-1])

# skip transitions

_p_prev = T.inc_subtensor(_p_prev[active_skip_idxs + 2], p_prev[active_skip_idxs])

updated_log_p_prev = T.log(_p_prev) + common_factor

log_p_next = T.set_subtensor(

zeros[:active_next],

log_p_curr[:active_next] + updated_log_p_prev

)

return active_next, log_p_next

开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:26,

示例14: ctc_path_probs

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def ctc_path_probs(predict, Y, alpha=1e-4):

smoothed_predict = (1 - alpha) * predict[:, Y] + alpha * np.float32(1.) / Y.shape[0]

L = T.log(smoothed_predict)

zeros = T.zeros_like(L[0])

log_first = zeros

f_skip_idxs = ctc_create_skip_idxs(Y)

b_skip_idxs = ctc_create_skip_idxs(Y[::-1]) # there should be a shortcut to calculating this

def step(log_f_curr, log_b_curr, f_active, log_f_prev, b_active, log_b_prev):

f_active_next, log_f_next = ctc_update_log_p(f_skip_idxs, zeros, f_active, log_f_curr, log_f_prev)

b_active_next, log_b_next = ctc_update_log_p(b_skip_idxs, zeros, b_active, log_b_curr, log_b_prev)

return f_active_next, log_f_next, b_active_next, log_b_next

[f_active, log_f_probs, b_active, log_b_probs], _ = theano.scan(

step, sequences=[L, L[::-1, ::-1]], outputs_info=[np.int32(1), log_first, np.int32(1), log_first])

idxs = T.arange(L.shape[1]).dimshuffle('x', 0)

mask = (idxs < f_active.dimshuffle(0, 'x')) & (idxs < b_active.dimshuffle(0, 'x'))[::-1, ::-1]

log_probs = log_f_probs + log_b_probs[::-1, ::-1] - L

return log_probs, mask

开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:23,

示例15: _project_im_rois

​点赞 6

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def _project_im_rois(im_rois, scales):

"""Project image RoIs into the image pyramid built by _get_image_blob.

Arguments:

im_rois (ndarray): R x 4 matrix of RoIs in original image coordinates

scales (list): scale factors as returned by _get_image_blob

Returns:

rois (ndarray): R x 4 matrix of projected RoI coordinates

levels (list): image pyramid levels used by each projected RoI

"""

im_rois = im_rois.astype(np.float, copy=False)

if len(scales) > 1:

widths = im_rois[:, 2] - im_rois[:, 0] + 1

heights = im_rois[:, 3] - im_rois[:, 1] + 1

areas = widths * heights

scaled_areas = areas[:, np.newaxis] * (scales[np.newaxis, :] ** 2)

diff_areas = np.abs(scaled_areas - 224 * 224)

levels = diff_areas.argmin(axis=1)[:, np.newaxis]

else:

levels = np.zeros((im_rois.shape[0], 1), dtype=np.int)

rois = im_rois * scales[levels]

return rois, levels

开发者ID:Sunarker,项目名称:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代码行数:26,

示例16: setup_buffer

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def setup_buffer(width, height):

"""Set up the internal pixel buffer.

:param width: width of buffer, ideally in multiples of 16

:param height: height of buffer, ideally in multiples of 16

"""

global _buffer_width, _buffer_height, _buf

_buffer_width = width

_buffer_height = height

_buf = numpy.zeros((_buffer_width, _buffer_height, 3), dtype=int)

开发者ID:pimoroni,项目名称:unicorn-hat-hd,代码行数:14,

示例17: compute_mfcc

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def compute_mfcc(audio, **kwargs):

"""

Compute the MFCC for a given audio waveform. This is

identical to how DeepSpeech does it, but does it all in

TensorFlow so that we can differentiate through it.

"""

batch_size, size = audio.get_shape().as_list()

audio = tf.cast(audio, tf.float32)

# 1. Pre-emphasizer, a high-pass filter

audio = tf.concat((audio[:, :1], audio[:, 1:] - 0.97*audio[:, :-1], np.zeros((batch_size,1000),dtype=np.float32)), 1)

# 2. windowing into frames of 320 samples, overlapping

windowed = tf.stack([audio[:, i:i+400] for i in range(0,size-320,160)],1)

# 3. Take the FFT to convert to frequency space

ffted = tf.spectral.rfft(windowed, [512])

ffted = 1.0 / 512 * tf.square(tf.abs(ffted))

# 4. Compute the Mel windowing of the FFT

energy = tf.reduce_sum(ffted,axis=2)+1e-30

filters = np.load("filterbanks.npy").T

feat = tf.matmul(ffted, np.array([filters]*batch_size,dtype=np.float32))+1e-30

# 5. Take the DCT again, because why not

feat = tf.log(feat)

feat = tf.spectral.dct(feat, type=2, norm='ortho')[:,:,:26]

# 6. Amplify high frequencies for some reason

_,nframes,ncoeff = feat.get_shape().as_list()

n = np.arange(ncoeff)

lift = 1 + (22/2.)*np.sin(np.pi*n/22)

feat = lift*feat

width = feat.get_shape().as_list()[1]

# 7. And now stick the energy next to the features

feat = tf.concat((tf.reshape(tf.log(energy),(-1,width,1)), feat[:, :, 1:]), axis=2)

return feat

开发者ID:rtaori,项目名称:Black-Box-Audio,代码行数:42,

示例18: get_logits

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def get_logits(new_input, length, first=[]):

"""

Compute the logits for a given waveform.

First, preprocess with the TF version of MFC above,

and then call DeepSpeech on the features.

"""

# new_input = tf.Print(new_input, [tf.shape(new_input)])

# We need to init DeepSpeech the first time we're called

if first == []:

first.append(False)

# Okay, so this is ugly again.

# We just want it to not crash.

tf.app.flags.FLAGS.alphabet_config_path = "DeepSpeech/data/alphabet.txt"

DeepSpeech.initialize_globals()

print('initialized deepspeech globals')

batch_size = new_input.get_shape()[0]

# 1. Compute the MFCCs for the input audio

# (this is differentable with our implementation above)

empty_context = np.zeros((batch_size, 9, 26), dtype=np.float32)

new_input_to_mfcc = compute_mfcc(new_input)[:, ::2]

features = tf.concat((empty_context, new_input_to_mfcc, empty_context), 1)

# 2. We get to see 9 frames at a time to make our decision,

# so concatenate them together.

features = tf.reshape(features, [new_input.get_shape()[0], -1])

features = tf.stack([features[:, i:i+19*26] for i in range(0,features.shape[1]-19*26+1,26)],1)

features = tf.reshape(features, [batch_size, -1, 19*26])

# 3. Whiten the data

mean, var = tf.nn.moments(features, axes=[0,1,2])

features = (features-mean)/(var**.5)

# 4. Finally we process it with DeepSpeech

logits = DeepSpeech.BiRNN(features, length, [0]*10)

return logits

开发者ID:rtaori,项目名称:Black-Box-Audio,代码行数:42,

示例19: evaluate

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def evaluate(self, points):

points = atleast_2d(points)

d, m = points.shape

if d != self.d:

if d == 1 and m == self.d:

# points was passed in as a row vector

points = reshape(points, (self.d, 1))

m = 1

else:

msg = "points have dimension %s, dataset has dimension %s" % (d,

self.d)

raise ValueError(msg)

result = zeros((m,), dtype=np.float)

if m >= self.n:

# there are more points than data, so loop over data

for i in range(self.n):

diff = self.dataset[:, i, newaxis] - points

tdiff = dot(self.inv_cov, diff)

energy = sum(diff*tdiff,axis=0) / 2.0

result = result + exp(-energy)

else:

# loop over points

for i in range(m):

diff = self.dataset - points[:, i, newaxis]

tdiff = dot(self.inv_cov, diff)

energy = sum(diff * tdiff, axis=0) / 2.0

result[i] = sum(exp(-energy), axis=0)

result = result / self._norm_factor

return result

开发者ID:svviz,项目名称:svviz,代码行数:36,

示例20: one_hot

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def one_hot(y, fill_k=False, one_not=False):

"""Map to one-hot encoding."""

# Check labels

labels = np.unique(y)

# Number of classes

K = len(labels)

# Number of samples

N = y.shape[0]

# Preallocate array

if one_not:

Y = -np.ones((N, K))

else:

Y = np.zeros((N, K))

# Set k-th column to 1 for n-th sample

for n in range(N):

# Map current class to index label

y_n = (y[n] == labels)

if fill_k:

Y[n, y_n] = y_n

else:

Y[n, y_n] = 1

return Y, labels

开发者ID:wmkouw,项目名称:libTLDA,代码行数:31,

示例21: psi

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def psi(self, X, theta, w, K=2):

"""

Compute psi function.

Parameters

----------

X : array

data set (N samples by D features)

theta : array

classifier parameters (D features by 1)

w : array

importance-weights (N samples by 1)

K : int

number of classes (def: 2)

Returns

-------

psi : array

array with psi function values (N samples by K classes)

"""

# Number of samples

N = X.shape[0]

# Preallocate psi array

psi = np.zeros((N, K))

# Loop over classes

for k in range(K):

# Compute feature statistics

Xk = self.feature_stats(X, k*np.ones((N, 1)))

# Compute psi function

psi[:, k] = (w*np.dot(Xk, theta))[:, 0]

return psi

开发者ID:wmkouw,项目名称:libTLDA,代码行数:38,

示例22: posterior

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def posterior(self, psi):

"""

Class-posterior estimation.

Parameters

----------

psi : array

weighted data-classifier output (N samples by K classes)

Returns

-------

pyx : array

class-posterior estimation (N samples by K classes)

"""

# Data shape

N, K = psi.shape

# Preallocate array

pyx = np.zeros((N, K))

# Subtract maximum value for numerical stability

psi = (psi.T - np.max(psi, axis=1).T).T

# Loop over classes

for k in range(K):

# Estimate posterior p^(Y=y | x_i)

pyx[:, k] = np.exp(psi[:, k]) / np.sum(np.exp(psi), axis=1)

return pyx

开发者ID:wmkouw,项目名称:libTLDA,代码行数:33,

示例23: test_fit_semi

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def test_fit_semi():

"""Test for fitting the model."""

X = rnd.randn(10, 2)

y = np.hstack((np.zeros((5,)), np.ones((5,))))

Z = rnd.randn(10, 2) + 1

u = np.array([[0, 0], [9, 1]])

clf = SemiSubspaceAlignedClassifier()

clf.fit(X, y, Z, u)

assert clf.is_trained

开发者ID:wmkouw,项目名称:libTLDA,代码行数:11,

示例24: test_predict_semi

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def test_predict_semi():

"""Test for making predictions."""

X = rnd.randn(10, 2)

y = np.hstack((np.zeros((5,)), np.ones((5,))))

Z = rnd.randn(10, 2) + 1

u = np.array([[0, 0], [9, 1]])

clf = SemiSubspaceAlignedClassifier()

clf.fit(X, y, Z, u)

u_pred = clf.predict(Z)

labels = np.unique(y)

assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0

开发者ID:wmkouw,项目名称:libTLDA,代码行数:13,

示例25: test_fit

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def test_fit():

"""Test for fitting the model."""

X = rnd.randn(10, 2)

y = np.hstack((np.zeros((5,)), np.ones((5,))))

Z = rnd.randn(10, 2) + 1

clf = RobustBiasAwareClassifier()

clf.fit(X, y, Z)

assert clf.is_trained

开发者ID:wmkouw,项目名称:libTLDA,代码行数:10,

示例26: test_predict

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def test_predict():

"""Test for making predictions."""

X = rnd.randn(10, 2)

y = np.hstack((np.zeros((5,)), np.ones((5,))))

Z = rnd.randn(10, 2) + 1

clf = RobustBiasAwareClassifier()

clf.fit(X, y, Z)

u_pred = clf.predict(Z)

labels = np.unique(y)

assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0

开发者ID:wmkouw,项目名称:libTLDA,代码行数:12,

示例27: test_fit

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def test_fit():

"""Test for fitting the model."""

X = np.vstack((rnd.randn(5, 2), rnd.randn(5, 2)+1))

y = np.hstack((np.zeros((5,)), np.ones((5,))))

Z = np.vstack((rnd.randn(5, 2)-1, rnd.randn(5, 2)+2))

clf = TargetContrastivePessimisticClassifier(l2=0.1)

clf.fit(X, y, Z)

assert clf.is_trained

开发者ID:wmkouw,项目名称:libTLDA,代码行数:10,

示例28: test_init

​点赞 5

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import zeros [as 别名]

def test_init():

"""Test for object type."""

clf = StructuralCorrespondenceClassifier()

assert type(clf) == StructuralCorrespondenceClassifier

assert not clf.is_trained

# def test_fit():

# """Test for fitting the model."""

# X = np.vstack((rnd.randn(5, 2), rnd.randn(5, 2)+1))

# y = np.hstack((np.zeros((5,)), np.ones((5,))))

# Z = np.vstack((rnd.randn(5, 2)-1, rnd.randn(5, 2)+2))

# clf = StructuralCorrespondenceClassifier(l2=1.0)

# clf.fit(X, y, Z)

# assert clf.is_trained

# def test_predict():

# """Test for making predictions."""

# X = np.vstack((rnd.randn(5, 2), rnd.randn(5, 2)+1))

# y = np.hstack((np.zeros((5,)), np.ones((5,))))

# Z = np.vstack((rnd.randn(5, 2)-1, rnd.randn(5, 2)+2))

# clf = StructuralCorrespondenceClassifier(l2=1.0)

# clf.fit(X, y, Z)

# u_pred = clf.predict(Z)

# labels = np.unique(y)

# assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0

开发者ID:wmkouw,项目名称:libTLDA,代码行数:29,

注:本文中的numpy.zeros方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

python中np zeros_Python numpy.zeros方法代码示例相关推荐

  1. python fmod函数_Python numpy.fmod方法代码示例

    本文整理汇总了Python中numpy.fmod方法的典型用法代码示例.如果您正苦于以下问题:Python numpy.fmod方法的具体用法?Python numpy.fmod怎么用?Python ...

  2. python中的scaler_Python preprocessing.MaxAbsScaler方法代码示例

    本文整理汇总了Python中sklearn.preprocessing.MaxAbsScaler方法的典型用法代码示例.如果您正苦于以下问题:Python preprocessing.MaxAbsSc ...

  3. python中string.digits_Python string.hexdigits方法代码示例

    本文整理汇总了Python中string.hexdigits方法的典型用法代码示例.如果您正苦于以下问题:Python string.hexdigits方法的具体用法?Python string.he ...

  4. pythoninterp error_Python numpy.interp方法代码示例

    本文整理汇总了Python中numpy.interp方法的典型用法代码示例.如果您正苦于以下问题:Python numpy.interp方法的具体用法?Python numpy.interp怎么用?P ...

  5. python get score gain_Python functional.linear方法代码示例

    本文整理汇总了Python中torch.nn.functional.linear方法的典型用法代码示例.如果您正苦于以下问题:Python functional.linear方法的具体用法?Pytho ...

  6. python cv2模块imshow_Python cv2.imshow方法代码示例

    本文整理汇总了Python中cv2.imshow方法的典型用法代码示例.如果您正苦于以下问题:Python cv2.imshow方法的具体用法?Python cv2.imshow怎么用?Python ...

  7. fmod函数python_python fmod函数_Python numpy.fmod方法代码示例

    本文整理汇总了Python中numpy.fmod方法的典型用法代码示例.如果您正苦于以下问题:Python numpy.fmod方法的具体用法?Python numpy.fmod怎么用?Python ...

  8. python iteritems函数_Python six.iteritems方法代码示例

    本文整理汇总了Python中sklearn.externals.six.iteritems方法的典型用法代码示例.如果您正苦于以下问题:Python six.iteritems方法的具体用法?Pyth ...

  9. python label函数_Python pyplot.clabel方法代码示例

    本文整理汇总了Python中matplotlib.pyplot.clabel方法的典型用法代码示例.如果您正苦于以下问题:Python pyplot.clabel方法的具体用法?Python pypl ...

最新文章

  1. 可持续农业生态系统中的核心微生物组
  2. Science公布年度十大科学突破!新冠疫苗居首位
  3. CTF---密码学入门第一题 这里没有key
  4. sgu 207 Robbers
  5. 小功能隐藏着大学问---windows的ACL带来的挑战
  6. postgres 错误duplicate key value violates unique constraint 解决方案
  7. GIS人眼中的“云GIS”
  8. 006 list类型
  9. 滴水穿石-07Java开发中常见的错误
  10. 【转】C#事件和委托的理解
  11. vi/vim编辑器常用命令
  12. 主力吸筹猛攻指标源码_通达信大于9000手大单指标公式,主力吸筹猛攻指标源码...
  13. Python菜鸟编程第十四课之正则表达式
  14. 基于TP-LINK(AC1200)主路由器+FAST(FWR303)副路由器的桥接(中继)信号放大
  15. VC编程调用dxdiag生成XML文件,来获取系统配置情况
  16. python爬取百部电影数据,我分析出了一个残酷的真相
  17. Matlab plotyy画2个纵坐标不同的图
  18. 应急响应 - Windows启动项分析,Windows计划任务分析,Windows服务分析
  19. VC++6.0 用gSoap客户端访问WebService
  20. Python - 统计某一列不同项的重复次数 并新增一列赋值

热门文章

  1. SLAM的起源及发展现状
  2. Mac学习第一步——Mac OS X系统常用多点触摸板操作手势
  3. mysql导出数据带表头
  4. 物联卡一直显示待激活怎么办_物联卡中心:物联网卡连不上4G的怎么解决?
  5. 发现一挺不错的批量命名工具
  6. 多揉人体5大黄金穴养生抗衰老
  7. Nginx的启动和关闭
  8. FGD · 它是 vue-next 操作文件的“御用”库
  9. 防晒(0x07 贪心)
  10. mysql的字符集修改_修改MySQL字符集