slice

Why does assigning past the end of a list via a slice not raise an IndexError? [duplicate]

落花浮王杯 提交于 2019-12-03 02:36:30
This question already has answers here : Why does substring slicing with index out of range work? (3 answers) I'm working on a sparse list implementation and recently implemented assignment via a slice. This led me to discover some behaviour in Python's built-in list implementation that I find suprising . Given an empty list and an assignment via a slice: >>> l = [] >>> l[100:] = ['foo'] I would have expected an IndexError from list here because the way this is implemented means that an item can't be retrieved from the specified index:: >>> l[100] Traceback (most recent call last): File "

Setting the pie slice colors in MPAndroidChart

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to define specific hex values for each slice in my pie chart. I'm following the wiki but the method doesn't seem to be working for PieDataSet PieDataSet dataSet = new PieDataSet(entries, "Fuel"); dataSet.setColors(new int[] { R.color.green1, R.color.green2, R.color.green3, R.color.green4 }, Context); These errors are shown: Cannot resolve symbol 'green1' Expression expected <-- At the 'Context' Is there an alternate way to set the pie slice color? This seems to work for Line charts but not for pie. 回答1: Found a work around: final int[

Why does Python allow out-of-range slice indexes for sequences?

点点圈 提交于 2019-12-03 02:31:15
问题 So I just came across what seems to me like a strange Python feature and wanted some clarification about it. The following array manipulation somewhat makes sense: p = [1,2,3] p[3:] = [4] p = [1,2,3,4] I imagine it is actually just appending this value to the end, correct? Why can I do this, however? p[20:22] = [5,6] p = [1,2,3,4,5,6] And even more so this: p[20:100] = [7,8] p = [1,2,3,4,5,6,7,8] This just seems like wrong logic. It seems like this should throw an error! Any explanation? -Is

Selecting a row of pandas series/dataframe by integer index

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am curious as to why df[2] is not supported, while df.ix[2] and df[2:3] both work. In [26]: df.ix[2] Out[26]: A 1.027680 B 1.514210 C -1.466963 D -0.162339 Name: 2000-01-03 00:00:00 In [27]: df[2:3] Out[27]: A B C D 2000-01-03 1.02768 1.51421 -1.466963 -0.162339 I would expect df[2] to work the same way as df[2:3] to be consistent with Python indexing convention. Is there a design reason for not supporting indexing row by single integer? 回答1: echoing @HYRY, see the new docs in 0.11 http://pandas.pydata.org/pandas-docs/stable/indexing.html

Playing multiple video using libvlc and Qt

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have created a sample application in Qt where i have to display camera stream in a 2x2 grid. I am using libvlc to play the stream and i am able to display the video as well. But i am facing few issues Vlc is creating a separate window to render the video. Its not displayed on the area provided by Qt Application. Here is my code void playerView::createPlayer() { const char *const vlc_args[] = { "--avcodec-hw=any", "--plugin-path=C:\QtSDK\vlc-2.2.1\plugins" }; vlcinstance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args); const

How to take column-slices of dataframe in pandas

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 选择语言 中文(简体) 日语 英语 中文(繁体) 由 翻译 强力驱动 问题: I load a some machine learning data from a csv file. The first 2 columns are observations and the remaining columns are features. Currently, I do the following : data = pandas . read_csv ( 'mydata.csv' ) which gives something like: data = pandas . DataFrame ( np . random . rand ( 10 , 5 ), columns = list ( 'abcde' )) I'd like to slice this dataframe in two dataframes: one containing the columns a and b and one containing the columns c , d and e . It is not possible to write something like observations =

How to know linux scheduler time slice?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm looking for the value of the time slice (or quantum) of my Linux kernel. Is there a /proc file which expose such an information ? (Or) Is it well-defined in the Linux header of my distributions ? (Or) Is there a C function of the Linux API (maybe sysinfo) that expose this value ? Thanks in advance. 回答1: The default Linux timeslice for realtime processes is defined in the Linux kernel as RR_TIMESLICE in include/linux/sched/rt.h . /* * default timeslice is 100 msecs (used only for SCHED_RR tasks). * Timeslices get refilled after they

Django slice a single field in a queryset

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to grab the first five characters from a char field but for only one field in a queryset but I keep getting various errors. Is there an effective way to do this in the view? Code I am trying: var = Model . objects . values ( 'field1' , 'field2' [: 5 ], 'field3' ) 回答1: You can annotate the queryset with first 5 letters of field2 using Substr function: from django . db . models . functions import Substr queryset = Model . objects . all () queryset = queryset . annotate ( field2_5 = Substr ( 'field2' , 1 , 5 )) And, then

Insert new item in array on any position in PHP

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I insert a new item into an array on any position, for example in the middle of array? 回答1: You may find this a little more intuitive. It only requires one function call to array_splice : $original = array( 'a', 'b', 'c', 'd', 'e' ); $inserted = array( 'x' ); // Not necessarily an array array_splice( $original, 3, 0, $inserted ); // splice in at position 3 // $original is now a b c x d e 回答2: A function that can insert at both integer and string positions: /** * @param array $array * @param int|string $position * @param mixed $insert

How do I make processes able to write in an array of the main program?

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am making a process pool and each of them need to write in different parts of a matrix that exists in the main program. There exists no fear of overwriting information as each process will work with different rows of the matrix. How can i make the matrix writable from within the processes?? The program is a matrix multiplier a professor assigned me and has to be multiprocessed. It will create a process for every core the computer has. The main program will send different parts of the matrix to the processes and they will compute them, then