slice

Slice assignment to tensorflow variable

爱⌒轻易说出口 提交于 2019-12-22 18:26:17
问题 I am trying to assign values to slice of a variable in tensorflow, but the following error is shown: 'ValueError: Sliced assignment is only supported for variables'. Why is this error showing even though I am trying to do slice assignment to a variable. My code is something like this: var1 = var1[startx:endx,starty:endy].assign(tf.ones([endx-startx,endy-starty],dtype=tf.int32)) where var1 is a tensorflow variable. 回答1: The other answer is correct; doing any operation to a tf variable does not

切片面试题:学习切片长度、容量,切片增长的过程

假如想象 提交于 2019-12-22 16:15:44
关于切片的面试题:摘自 https://goquiz.github.io/#subslice-grow func Subslice() { s := []int{1, 2, 3,4,5,6,7,8,9} ss := s[3:6] fmt.Printf("len ss : %d\n", len(ss)) fmt.Printf("Cap ss : %d\n", cap(ss)) ss = append(ss, 4) fmt.Printf("len ss : %d\n", len(ss)) fmt.Printf("Cap ss : %d\n", cap(ss)) for _, v := range ss { v += 10 } for i := range ss { ss[i] += 10 } fmt.Println(s) } 大家可以看一下结果是什么,结果是: len ss : 3 Cap ss : 6 len ss : 4 Cap ss : 6 [1 2 3 14 15 16 14 8 9 0 1 3] 下面是解析过程: 首先ss := s[3:6],结果就是截取索引在[3, 6)上的数据,所以len(ss)是3,那ss的cap容量为啥是9呢? 一个切片的容量就是该切面在底层数组山的开始位置向右扩展至数组的结束位置,在这边就是索引位置3到索引位置8 ,一共六个元素,append(

Determining the last file chunk

左心房为你撑大大i 提交于 2019-12-22 13:59:18
问题 I'm trying to setup a file upload through rest for large files. The function below is taking care of chunking but I need to be able to recognize the last chunk because my rest call changes to /finishUpload() in order to commit the save. Right now I'm only able to figure out when the blob is empty but I can't figure out how to determine the last iteration before the blob is empty. This is the script I'm using below to parse my files. export default function parseFile(file, options) { var opts

Delete all elements in an array corresponding to Boolean mask

大兔子大兔子 提交于 2019-12-22 11:22:26
问题 I have a Boolean mask that exists as 2-D numpy array (Boolean Array) array([[ True, True, True, True, True, True, True], [ True, True, True, True, True, True, True], [ True, True, True, True, True, True, True], [ True, True, True, True, True, True, True], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False]], dtype=bool) I also have a separate 2-D numpy array of values that is of the same

How to slice a batch and apply an operation on each slice in TensorFlow

心不动则不痛 提交于 2019-12-22 10:29:08
问题 I am a beginner with TensorFlow, I am trying to implement a function that takes a batch as input. It has to slice this batch into several ones, apply some operations on them, then concatenate them to build a new tensor to return. Through my readings, I found there are some implemented function like input_slice_producer and batch_join but I didn't get to work with them. I attached what I've found as solution below, but it's kinda slow, not proper and incapable of detecting the current size of

Theano tensor slicing… how to use boolean to slice?

假装没事ソ 提交于 2019-12-22 10:14:36
问题 In numpy, if I have a boolean array, I can use it to select elements of another array: >>> import numpy as np >>> x = np.array([1, 2, 3]) >>> idx = np.array([True, False, True]) >>> x[idx] array([1, 3]) I need to do this in theano. This is what I tried, but I got an unexpected result. >>> from theano import tensor as T >>> x = T.vector() >>> idx = T.ivector() >>> y = x[idx] >>> y.eval({x: np.array([1,2,3]), idx: np.array([True, False, True])}) array([ 2., 1., 2.]) Can someone explain the

How can I slice a string like Python does in Perl 6?

ぃ、小莉子 提交于 2019-12-22 09:36:53
问题 In Python, I can splice string like this: solo = A quick brown fox jump over the lazy dog solo[3:5] I know substr and comb is enough, I want to know if it's possible, However. Should I use a role to do this? 回答1: How to slice a string Strings (represented as class Str ) are seen as single values and not positional data structures in Perl 6, and thus can't be indexed/sliced with the built-in [ ] array indexing operator. As you already suggested, comb or substr is the way to go: my $solo = "A

Using a string to define Numpy array slice

不羁的心 提交于 2019-12-22 07:59:42
问题 I have an image array that has an X times Y shape of 2048x2088. The x-axis has two 20 pixel regions, one at the start and one at the end, which are used to calibrate the main image area. To access these regions I can slice the array like so: prescan_area = img[:, :20] data_area = img[:, 20:2068] overscan_area = img[:, 2068:] My question is how to define these areas in a configuration file in order the generalise this slice for other cameras which may have different prescan and overscan areas

Slicing a nested hash in Perl

馋奶兔 提交于 2019-12-22 06:49:32
问题 Say I have a hash that I can index as: $hash{$document}{$word} From what I read online (although I could not find this on perlreftut, perldsc or perllol), I can slice a hash using a list if I use the @ prefix on my hash to indicate that I want the hash to return a list. However, if I try to slice my hash using a list @list : @%hash{$document}{@list} I get several "Scalar values ... better written" errors. How can I slash a nested hash in Perl? 回答1: The sigill for your hash must be @ , like so

How to slice a dataframe by selecting a range of columns and rows based on names and not indexes?

守給你的承諾、 提交于 2019-12-22 05:29:21
问题 This is a follow-up question of the question I asked here. There I learned a) how to do this for columns (see below) and b) that the selection of rows and columns seems to be quite differently handled in R which means that I cannot use the same approach for rows. So suppose I have a pandas dataframe like this: import pandas as pd import numpy as np df = pd.DataFrame(np.random.randint(10, size=(6, 6)), columns=['c' + str(i) for i in range(6)], index=["r" + str(i) for i in range(6)]) c0 c1 c2