range

Create list of square powers of numbers in range using generator

蓝咒 提交于 2019-12-06 02:54:42
问题 I'd like to rewrite this part of code using generator : basic = [] for x in range(0,11): basic.append(x**2) How can I do this ? Tried : basic.append(x**2 for x in range(0,11)) but it raises syntax error in x**2 part. 回答1: You'd be better off using list comprehension: basic = [x*x for x in range(11)] 回答2: You are mistaken; your code doesn't produce a syntax error, it just does the wrong thing: >>> basic = [] >>> basic.append(x**2 for x in range(0,11)) >>> basic [<generator object <genexpr> at

Same color bar range for different plots - Matplotlib

有些话、适合烂在心里 提交于 2019-12-06 02:52:51
I'm struggling to keep the same color bar range through different plots. For example, I have these visualizations: Which are produced with this code: def plot_contour(x_dim, y_dim, x_steps, y_steps, scalar_field, file_path): plt.figure() x, y = numpy.mgrid[-x_dim:x_dim/:x_steps*1j, -y_dim:y_dim:y_steps*1j] cs = plt.contourf(x, y, scalar_field, zorder=1, extent=[-x_dim, x_dim, -y_dim, y_dim]) plt.colorbar(cs) plt.savefig(file_path + '.png', dpi=Vc.dpi) plt.close() I want to be able to compare both fields, so, I would like to use the same color mapping for both of them. My first approach was to

Translate numbers from a range to another range

ⅰ亾dé卋堺 提交于 2019-12-06 02:44:51
Example range 1 (minimum and maximum): [40 ... 480] Example numbers from range 1: [42, 59.4, 78.18, 120.43, 416] Example range 2: [10 .. 140] How can I translate the values of the numbers from range 1 to values within the second range? 42 should be equivalent to something between 10 and 11 in the new range. I'm using PHP but this is more like a math problem. I know how to align them to the second range: $diff = $range[0] - $numbers[0]; foreach($numbers as $i => $number){ $numbers[$i] = $number + $diff; } But that's it :( You can transform one of the ranges into the other with this function

How to show frequencies in discrete categories with range data in R?

限于喜欢 提交于 2019-12-06 01:49:17
I'm trying to sort out a bunch of data that I have about dinosaurs and their age ranges. So far, my data consists of a column of names, and then two columns of maximum and minimum dates in millions of years in the past, as you can see here: GENUS ma_max ma_min ma_mid Abydosaurus 109 94.3 101.65 Achelousaurus 84.9 70.6 77.75 Acheroraptor 70.6 66.043 68.3215 Geological time is split into different ages (such as the Jurassic and Cretaceous) and these are also subdivided into stage. These stages have specific age ranges and I have made a dataframe to display these: Stage ma_max ma_min ma_mid

Range intersection / union

。_饼干妹妹 提交于 2019-12-06 01:27:28
I'm developing a programming language for which I want to provide a Range data type which for now is, not as usually, a list of pairs of int values (x,y) with the constraint that x < y . I say not as usually because usually a range is just a pair but in my case it is more than than, allowing to have for example 1 to 5, 7 to 11, 13 to 22 all contained in a single object. I would like to provide two functions to generate the union and the instersection of two ranges, that should contain the least number of non-overlapping intervals from a couple of ranges.. so for example 1 to 5 || 3 to 8 = 1 to

Highlight/select multiple divs with ranges w/ contenteditable?

孤人 提交于 2019-12-06 01:00:03
问题 Let's say I have a set of contenteditable="true" divs. <div id="0" contenteditable="true"></div> <div id="1" contenteditable..></div> <div...etc></div> I can't have one div, multiple divs is a must. How could I highlight the content of more than one div? Using ranges? Anything else? 回答1: The answer is that it depends on the browser. See this example for a test of two methods using Ranges. The first attempts to create a Range per editable <div> and add all of them to the selection. The second

Mapping a range of values to another value

纵然是瞬间 提交于 2019-12-05 21:38:01
I'm trying to find a efficient way to map a range of values to another value.For example 1-9 -> 49 10-24 ->54 25-49 -> 59 50-74 -> 50 75-99 -> 49 100-150 -> 40 Here the values don't follow any regular patters.One solution is to use conditional statements ( if -else ) but as the set of values increase the number of statements increase and it will be hard to maintain.So is there any other elegant and efficient way to achieve this ? Since the ranges are consecutive, you can try to map them by the start number, and then find the value with a dichotomic search: var map = [ [1, 49], [10, 54], [25,

double type digits in C++

折月煮酒 提交于 2019-12-05 21:35:28
The IEE754 (64 bits) floating point is supposed to correctly represent 15 significant digit although the internal representation has 17 ditigs. Is there a way to force the 16th and 17th digits to zero ?? Ref: http://msdn.microsoft.com/en-us/library/system.double(VS.80).aspx : . . Remember that a floating-point number can only approximate a decimal number, and that the precision of a floating-point number determines how accurately that number approximates a decimal number. By default, a Double value contains 15 decimal digits of precision, although a maximum of 17 digits is maintained

Is there a way to find a range within a range in Excel?

南楼画角 提交于 2019-12-05 21:19:44
I have an xls file that looks this way: http://i.stack.imgur.com/d2fux.png Well, and that's sth like the same piece of info that depends on the headers, in this case the header is the row 22164, next header is 22178, and so on. In the GUI, i have something that let users choose from parameters, and option to load the info from the xls file depending on their choices, for example, they can choose: WR | random | 4 | 6 | 15 looking in that case for the info stored in A22165:O22177 I have already the sheet with all the info in the workbook, let's call that object[,] 'valueArray': Workbook workBook

Google Apps Script to Email Active Spreadsheet

余生长醉 提交于 2019-12-05 21:17:02
I found a script online that takes the current sheet, copies it to a temporary new spreadsheet, converts it to PDF and emails it. I was able to get it working but trying to set it up so that it only sends a certain range. Tried to play with it a bit but I am not a good coder by any stretch. Alternatively I'd be interested also in figuring out how to get it to fit to 1 page PDF in landscape, convert without gridlines (my online research shows this ins't possible?) or even send as XLS. // Simple function to send Weekly Status Sheets to contacts listed on the "Contacts" sheet in the MPD. // Load