當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.range方法代碼示例

本文整理匯總了Python中numpy.range方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.range方法的具體用法?Python numpy.range怎麽用?Python numpy.range使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.range方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_graph_nbrhd_paths

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def get_graph_nbrhd_paths(train_graph, ent, exclude_tuple):
  """Helper to get neighbor (rels, ents) excluding a particular tuple."""
  es, er, et = exclude_tuple
  neighborhood = []
  for i in range(train_graph.max_path_length):
    if ent == es:
      paths = _proc_paths(train_graph.paths[i][ent], er, et,
                          train_graph.max_path_length,
                          (train_graph.rel_pad, train_graph.ent_pad))
    else:
      paths = _proc_paths(train_graph.paths[i][ent],
                          max_length=train_graph.max_path_length,
                          pad=(train_graph.rel_pad, train_graph.ent_pad))
    neighborhood += paths
  if not neighborhood:
    neighborhood = [[]]
  neighborhood = np.array(neighborhood, dtype=np.int)
  return neighborhood 
開發者ID:tensorflow,項目名稱:neural-structured-learning,代碼行數:20,代碼來源:dataset.py

示例2: ot2bio_ote

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def ot2bio_ote(ote_tag_sequence):
    """
    ot2bio function for ote tag sequence
    :param ote_tag_sequence:
    :return:
    """
    new_ote_sequence = []
    n_tag = len(ote_tag_sequence)
    prev_ote_tag = '$$$'
    for i in range(n_tag):
        cur_ote_tag = ote_tag_sequence[i]
        assert cur_ote_tag == 'O' or cur_ote_tag == 'T'
        if cur_ote_tag == 'O':
            new_ote_sequence.append(cur_ote_tag)
        else:
            # cur_ote_tag is T
            if prev_ote_tag == 'T':
                new_ote_sequence.append('I')
            else:
                # cur tag is at the beginning of the opinion target
                new_ote_sequence.append('B')
        prev_ote_tag = cur_ote_tag
    return new_ote_sequence 
開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:25,代碼來源:utils.py

示例3: ot2bieos_batch

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def ot2bieos_batch(ote_tags, ts_tags):
    """
    batch version of function ot2bieos
    :param ote_tags: a batch of ote tag sequence
    :param ts_tags: a batch of ts tag sequence
    :return:
    :param ote_tags:
    :param ts_tags:
    :return:
    """
    new_ote_tags, new_ts_tags = [], []
    assert len(ote_tags) == len(ts_tags)
    n_seqs = len(ote_tags)
    for i in range(n_seqs):
        ote, ts = ot2bieos(ote_tag_sequence=ote_tags[i], ts_tag_sequence=ts_tags[i])
        new_ote_tags.append(ote)
        new_ts_tags.append(ts)
    return new_ote_tags, new_ts_tags 
開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:20,代碼來源:utils.py

示例4: bio2ot_batch

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def bio2ot_batch(ote_tags, ts_tags):
    """
    batch version of function bio2ot
    :param ote_tags: a batch of ote tag sequence
    :param ts_tags: a batch of ts tag sequence
    :return:
    """
    new_ote_tags, new_ts_tags = [], []
    assert len(ote_tags) == len(ts_tags)
    n_seqs = len(ote_tags)
    for i in range(n_seqs):
        ote, ts = bio2ot(ote_tag_sequence=ote_tags[i], ts_tag_sequence=ts_tags[i])
        new_ote_tags.append(ote)
        new_ts_tags.append(ts)
    return new_ote_tags, new_ts_tags


# TODO 
開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:20,代碼來源:utils.py

示例5: set_cid

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def set_cid(dataset, char_vocab):
    """
    set cid field for the records in the dataset
    :param dataset: dataset
    :param char_vocab: vocabulary of character
    :return:
    """
    n_records = len(dataset)
    cids = []
    for i in range(n_records):
        words = dataset[i]['words']
        cids = []
        for w in words:
            cids.append([char_vocab[ch] for ch in list(w)])
        dataset[i]['cids'] = list(cids)
    return dataset 
開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:18,代碼來源:utils.py

示例6: conv_tower

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def conv_tower(inputs, filters_init, filters_mult=1, repeat=1, **kwargs):
  """Construct a reducing convolution block.

  Args:
    inputs:        [batch_size, seq_length, features] input sequence
    filters_init:  Initial Conv1D filters
    filters_mult:  Multiplier for Conv1D filters
    repeat:        Conv block repetitions

  Returns:
    [batch_size, seq_length, features] output sequence
  """

  # flow through variable current
  current = inputs

  # initialize filters
  rep_filters = filters_init

  for ri in range(repeat):
    # convolution
    current = conv_block(current,
      filters=int(np.round(rep_filters)),
      **kwargs)

    # update filters
    rep_filters *= filters_mult

  return current 
開發者ID:calico,項目名稱:basenji,代碼行數:31,代碼來源:blocks.py

示例7: xception_tower

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def xception_tower(inputs, filters_init, filters_mult=1, repeat=1, **kwargs):
  """Construct a reducing convolution block.

  Args:
    inputs:        [batch_size, seq_length, features] input sequence
    filters_init:  Initial Conv1D filters
    filters_mult:  Multiplier for Conv1D filters
    repeat:        Conv block repetitions

  Returns:
    [batch_size, seq_length, features] output sequence
  """

  # flow through variable current
  current = inputs

  # initialize filters
  rep_filters = filters_init

  for ri in range(repeat):
    # convolution
    current = xception_block(current,
      filters=int(np.round(rep_filters)),
      **kwargs)

    # update filters
    rep_filters *= filters_mult

  return current


############################################################
# Attention
############################################################ 
開發者ID:calico,項目名稱:basenji,代碼行數:36,代碼來源:blocks.py

示例8: position_encoding

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def position_encoding(current, min_rate=.0001):
  """Add original Transformer positional encodings,

  Args:
    current:  [batch_size, seq_length, features] sequence
    min_rate:

  Returns:
    sequence w/ positional encodings concatenated.
  """
  seq_length = current.shape[1].value
  features = current.shape[2].value

  assert(features % 2 == 0)

  # compute angle rates
  angle_rate_exponents = np.linspace(0, 1, features//2)
  angle_rates = min_rate**angle_rate_exponents

  # compute angle radians
  positions = np.range(seq_length)
  angle_rads = positions[:, np.newaxis] * angle_rates[np.newaxis, :]

  # sines and cosines
  sines = np.sin(angle_rads)
  cosines = np.cos(angle_rads)
  pos_encode = np.concatenate([sines, cosines], axis=-1)

  return current 
開發者ID:calico,項目名稱:basenji,代碼行數:31,代碼來源:blocks.py

示例9: dense_image_warp

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def dense_image_warp(image, flow):
    # batch_size, height, width, channels = (array_ops.shape(image)[0],
    #                                        array_ops.shape(image)[1],
    #                                        array_ops.shape(image)[2],
    #                                        array_ops.shape(image)[3])
    batch_size, height, width, channels = (np.shape(image)[0],
                                           np.shape(image)[1],
                                           np.shape(image)[2],
                                           np.shape(image)[3])

    # The flow is defined on the image grid. Turn the flow into a list of query
    # points in the grid space.
    # grid_x, grid_y = array_ops.meshgrid(
    #     math_ops.range(width), math_ops.range(height))
    # stacked_grid = math_ops.cast(
    #     array_ops.stack([grid_y, grid_x], axis=2), flow.dtype)
    # batched_grid = array_ops.expand_dims(stacked_grid, axis=0)
    # query_points_on_grid = batched_grid - flow
    # query_points_flattened = array_ops.reshape(query_points_on_grid,
    #                                            [batch_size, height * width, 2])
    grid_x, grid_y = np.meshgrid(
        np.range(width), np.range(height))
    stacked_grid = np.cast(
        np.stack([grid_y, grid_x], axis=2), flow.dtype)
    batched_grid = np.expand_dims(stacked_grid, axis=0)
    query_points_on_grid = batched_grid - flow
    query_points_flattened = np.reshape(query_points_on_grid,
                                        [batch_size, height * width, 2])
    # Compute values at the query points, then reshape the result back to the
    # image grid.
    interpolated = interp2d(image, query_points_flattened)
    interpolated = np.reshape(interpolated,
                              [batch_size, height, width, channels])
    return interpolated 
開發者ID:DemisEom,項目名稱:SpecAugment,代碼行數:36,代碼來源:sparse_image_warp_np.py

示例10: _sample_next_edges

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def _sample_next_edges(edges, to_sample):
  if len(edges) < to_sample:
    return edges
  sample_ids = np.random.choice(range(len(edges)), size=to_sample,
                                replace=False)
  return [edges[i] for i in sample_ids] 
開發者ID:tensorflow,項目名稱:neural-structured-learning,代碼行數:8,代碼來源:dataset.py

示例11: sample_or_pad

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def sample_or_pad(arr, max_size, pad_value=-1):
  """Helper to pad arr along axis 0 to max_size or subsample to max_size."""
  arr_shape = arr.shape
  if arr.size == 0:
    if isinstance(pad_value, list):
      result = np.ones((max_size, len(pad_value)), dtype=arr.dtype) * pad_value
    else:
      result = np.ones((max_size,), dtype=arr.dtype) * pad_value
  elif arr.shape[0] > max_size:
    if arr.ndim == 1:
      result = np.random.choice(arr, size=max_size, replace=False)
    else:
      idx = np.arange(arr.shape[0])
      np.random.shuffle(idx)
      result = arr[idx[:max_size], :]
  else:
    padding = np.ones((max_size-arr.shape[0],) + arr_shape[1:],
                      dtype=arr.dtype)
    if isinstance(pad_value, list):
      for i in range(len(pad_value)):
        padding[..., i] *= pad_value[i]
    else:
      padding *= pad_value
    result = np.concatenate((arr, padding), axis=0)
  # result = np.pad(arr,
  #                 [[0, max_size-arr.shape[0]]] + ([[0, 0]] * (arr.ndim-1)),
  #                 "constant", constant_values=pad_value)
  return result 
開發者ID:tensorflow,項目名稱:neural-structured-learning,代碼行數:30,代碼來源:dataset.py

示例12: ot2bio_ts

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def ot2bio_ts(ts_tag_sequence):
    """
    ot2bio function for ts tag sequence
    :param ts_tag_sequence:
    :return:
    """
    new_ts_sequence = []
    n_tag = len(ts_tag_sequence)
    prev_pos = '$$$'
    for i in range(n_tag):
        cur_ts_tag = ts_tag_sequence[i]
        if cur_ts_tag == 'O':
            new_ts_sequence.append('O')
            cur_pos = 'O'
        else:
            # current tag is subjective tag, i.e., cur_pos is T
            # print(cur_ts_tag)
            cur_pos, cur_sentiment = cur_ts_tag.split('-')
            if cur_pos == prev_pos:
                # prev_pos is T
                new_ts_sequence.append('I-%s' % cur_sentiment)
            else:
                # prev_pos is O
                new_ts_sequence.append('B-%s' % cur_sentiment)
        prev_pos = cur_pos
    return new_ts_sequence 
開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:28,代碼來源:utils.py

示例13: ot2bio_ote_batch

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def ot2bio_ote_batch(ote_tag_seqs):
    """
    batch version of function ot2bio_ote
    :param ote_tags:
    :return:
    """
    new_ote_tag_seqs = []
    n_seqs = len(ote_tag_seqs)
    for i in range(n_seqs):
        new_ote_seq = ot2bio_ote(ote_tag_sequence=ote_tag_seqs[i])
        new_ote_tag_seqs.append(new_ote_seq)
    return new_ote_tag_seqs 
開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:14,代碼來源:utils.py

示例14: ot2bio_ts_batch

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def ot2bio_ts_batch(ts_tag_seqs):
    """
    batch version of function ot2bio_ts
    :param ts_tag_seqs:
    :return:
    """
    new_ts_tag_seqs = []
    n_seqs = len(ts_tag_seqs)
    for i in range(n_seqs):
        new_ts_seq = ot2bio_ts(ts_tag_sequence=ts_tag_seqs[i])
        new_ts_tag_seqs.append(new_ts_seq)
    return new_ts_tag_seqs 
開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:14,代碼來源:utils.py

示例15: ot2bio_batch

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import range [as 別名]
def ot2bio_batch(ote_tags, ts_tags):
    """
    batch version of function ot2bio
    :param ote_tags: a batch of ote tag sequence
    :param ts_tags: a batch of ts tag sequence
    :return:
    """
    new_ote_tags, new_ts_tags = [], []
    assert len(ote_tags) == len(ts_tags)
    n_seqs = len(ote_tags)
    for i in range(n_seqs):
        ote, ts = ot2bio(ote_tag_sequence=ote_tags[i], ts_tag_sequence=ts_tags[i])
        new_ote_tags.append(ote)
        new_ts_tags.append(ts)
    return new_ote_tags, new_ts_tags 
開發者ID:hsqmlzno1,項目名稱:Transferable-E2E-ABSA,代碼行數:17,代碼來源:utils.py


注:本文中的numpy.range方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。