Search Results

Search found 4955 results on 199 pages for 'range'.

Page 34/199 | < Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >

  • Matplotlib autodatelocator custom date formatting?

    - by jawonlee
    I'm using Matplotlib to dynamically generate .png charts from a database. The user may set as the x-axis any given range of datetimes, and I need to account for all of it. While Matplotlib has the dates.AutoDateLocator(), I want the datetime format printed on the chart to be context-specific - e.g. if the user is charting from 3 p.m. to 5 p.m., the year/month/day information doesn't need to be displayed. Right now, I'm manually creating Locator and Formatter objects thusly: def get_ticks(start, end): from datetime import timedelta as td delta = end - start if delta <= td(minutes=10): loc = mdates.MinuteLocator() fmt = mdates.DateFormatter('%I:%M %p') elif delta <= td(minutes=30): loc = mdates.MinuteLocator(byminute=range(0,60,5)) fmt = mdates.DateFormatter('%I:%M %p') elif delta <= td(hours=1): loc = mdates.MinuteLocator(byminute=range(0,60,15)) fmt = mdates.DateFormatter('%I:%M %p') elif delta <= td(hours=6): loc = mdates.HourLocator() fmt = mdates.DateFormatter('%I:%M %p') elif delta <= td(days=1): loc = mdates.HourLocator(byhour=range(0,24,3)) fmt = mdates.DateFormatter('%I:%M %p') elif delta <= td(days=3): loc = mdates.HourLocator(byhour=range(0,24,6)) fmt = mdates.DateFormatter('%I:%M %p') elif delta <= td(weeks=2): loc = mdates.DayLocator() fmt = mdates.DateFormatter('%b %d') elif delta <= td(weeks=12): loc = mdates.WeekdayLocator() fmt = mdates.DateFormatter('%b %d') elif delta <= td(weeks=52): loc = mdates.MonthLocator() fmt = mdates.DateFormatter('%b') else: loc = mdates.MonthLocator(interval=3) fmt = mdates.DateFormatter('%b %Y') return loc,fmt Is there a better way of doing this?

    Read the article

  • Programming help Loop adding

    - by Deonna
    I know this probably really simple but Im not sure what im doing wrong... The assignment states: For the second program for this lab, you are to have the user enter an integer value in the range of 10 to 50. You are to verify that the user enters a value in that range, and continue to prompt him until he does give you a value in that range. After the user has successfully entered a value in that range, you are to display the sum of all the integers from 1 to the value entered. I have this so far: #include <iostream.h> int main () { int num, sum; cout << "do-while Loop Example 2" << endl << endl; do { cout << "Enter a value from 10 to 50: "; cin >> num; if (num < 10 || num > 50) cout << "Out of range; Please try again..." << endl; } while (num < 10 || num > 50); { int i; int sum = 0; for (num = 1; num <= 50; num ++) sum = sum + num; } cout << endl << "The sum is " << sum << endl; return 0; } Im just not sure exactly what i'm doing wrong... I keep getting the wrong sum for the total...

    Read the article

  • Wildcards vs. generic methods

    - by FredOverflow
    Is there any practical difference between the following approaches to print all elements in a range? public static void printA(Iterable<?> range) { for (Object o : range) { System.out.println(o); } } public static <T> void printB(Iterable<T> range) { for (T x : range) { System.out.println(x); } } Apparently, printB involves an additional checked cast to Object (see line 16), which seems rather stupid to me -- isn't everything an Object anyway? public static void printA(java.lang.Iterable); Code: 0: aload_0 1: invokeinterface #18, 1; //InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator; 6: astore_2 7: goto 24 10: aload_2 11: invokeinterface #24, 1; //InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object; 16: astore_1 17: getstatic #30; //Field java/lang/System.out:Ljava/io/PrintStream; 20: aload_1 21: invokevirtual #36; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V 24: aload_2 25: invokeinterface #42, 1; //InterfaceMethod java/util/Iterator.hasNext:()Z 30: ifne 10 33: return public static void printB(java.lang.Iterable); Code: 0: aload_0 1: invokeinterface #18, 1; //InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator; 6: astore_2 7: goto 27 10: aload_2 11: invokeinterface #24, 1; //InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object; 16: checkcast #3; //class java/lang/Object 19: astore_1 20: getstatic #30; //Field java/lang/System.out:Ljava/io/PrintStream; 23: aload_1 24: invokevirtual #36; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V 27: aload_2 28: invokeinterface #42, 1; //InterfaceMethod java/util/Iterator.hasNext:()Z 33: ifne 10 36: return

    Read the article

  • Problem with Clojure function

    - by Bozhidar Batsov
    Hi, everyone, I've started working yesterday on the Euler Project in Clojure and I have a problem with one of my solutions I cannot figure out. I have this function: (defn find-max-palindrom-in-range [beg end] (reduce max (loop [n beg result []] (if (>= n end) result (recur (inc n) (concat result (filter #(is-palindrom? %) (map #(* n %) (range beg end))))))))) I try to run it like this: (find-max-palindrom-in-range 100 1000) and I get this exception: java.lang.Integer cannot be cast to clojure.lang.IFn [Thrown class java.lang.ClassCastException] which I presume means that at some place I'm trying to evaluate an Integer as a function. I however cannot find this place and what puzzles me more is that everything works if I simply evaluate it like this: (reduce max (loop [n 100 result []] (if (>= n 1000) result (recur (inc n) (concat result (filter #(is-palindrom? %) (map #(* n %) (range 100 1000)))))))) (I've just stripped down the function definition and replaced the parameters with constants) Thanks in advance for your help and sorry that I probably bother you with idiotic mistake on my part. Btw I'm using Clojure 1.1 and the newest SLIME from ELPA.

    Read the article

  • Linq Queries converting to lambda expressions ?

    - by Freshblood
    Hello from item in range where item % 2 ==0 select i ; is converting to lamda expressions as below range.where(item % 2 ==0).select(x=>x). I feel that first way of linq is translating next one and if it is ,so is there any optimization like this range.where(item & 2 == 0) instead of other one ?

    Read the article

  • How do I set selection to Nothing when programming Excel using VBA?

    - by Curt
    When I create a graph after using range.copy and range.paste it leaves the paste range selected, and then when I create a graph a few lines later, it uses the selection as the first series in the plot. I can delete the series, but is there a more elegant way to do this? I tried Set selection = nothing but it won't let me set selection. I also tried selection.clear, but that just cleared the last cells that were selected, and still added an extra series to the plot. Curt

    Read the article

  • Performance Problem with Clojure Array

    - by dbyrne
    This piece of code is very slow. Execution from the slime-repl on my netbook takes a couple minutes. Am I doing something wrong? (def test-array (make-array Integer/TYPE 400 400 3)) (doseq [x (range 400), y (range 400), z (range 3)] (aset test-array x y z 0))

    Read the article

  • Detecting periodic repetitions in the data stream

    - by pulegium
    Let's say I have an array of zeros: a = numpy.zeros(1000) I then introduce some repetitive 'events': a[range(0, 1000, 30)] = 1 Question is, how do I detect the 'signal' there? Because it's far from the ideal signal if I do the 'regular' FFT I don't get a clear indication of where my 'true' signal is: f = abs(numpy.fft.rfft(a)) Is there a method to detect these repetitions with some degree of certainty? Especially if I have few of those mixed in, for example here: a[range(0, 1000, 30)] = 1 a[range(0, 1000, 110)] = 1 a[range(0, 1000, 48)] = 1 I'd like to get three 'spikes' on the resulting data...

    Read the article

  • Why is PLINQ slower than LINQ for this code?

    - by Rob Packwood
    First off, I am running this on a dual core 2.66Ghz processor machine. I am not sure if I have the .AsParallel() call in the correct spot. I tried it directly on the range variable too and that was still slower. I don't understand why... Here are my results: Process non-parallel 1000 took 146 milliseconds Process parallel 1000 took 156 milliseconds Process non-parallel 5000 took 5187 milliseconds Process parallel 5000 took 5300 milliseconds using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace DemoConsoleApp { internal class Program { private static void Main() { ReportOnTimedProcess( () => GetIntegerCombinations(), "non-parallel 1000"); ReportOnTimedProcess( () => GetIntegerCombinations(runAsParallel: true), "parallel 1000"); ReportOnTimedProcess( () => GetIntegerCombinations(5000), "non-parallel 5000"); ReportOnTimedProcess( () => GetIntegerCombinations(5000, true), "parallel 5000"); Console.Read(); } private static List<Tuple<int, int>> GetIntegerCombinations( int iterationCount = 1000, bool runAsParallel = false) { IEnumerable<int> range = Enumerable.Range(1, iterationCount); IEnumerable<Tuple<int, int>> integerCombinations = from x in range from y in range select new Tuple<int, int>(x, y); return runAsParallel ? integerCombinations.AsParallel().ToList() : integerCombinations.ToList(); } private static void ReportOnTimedProcess( Action process, string processName) { var stopwatch = new Stopwatch(); stopwatch.Start(); process(); stopwatch.Stop(); Console.WriteLine("Process {0} took {1} milliseconds", processName, stopwatch.ElapsedMilliseconds); } } }

    Read the article

  • How can i get the between cell addresses.

    - by Sathish
    I have a function which accepts fromRange and ToRange of an Excel cell. basically i want to read cell by cell values from the range. suppose if i pass E2 and E9 i want to read in a loop something like Range(E2).value, Range(E3).value and so on till E9 How can i get the between cell addresses. Please help

    Read the article

  • C++ domain specific embedded language operators

    - by aaa
    hi. In numerical oriented languages (Matlab, Fortran) range operator and semantics is very handy when working with multidimensional data. For example: A(i:j,k,:n) // represents two-dimensional slice B(i:j,0:n) of A at index k unfortunately C++ does not have range operator (:). of course it can be emulated using range/slice functor, but semantics is less clean than Matlab. I am prototyping matrix/tensor domain language in C++ and am wondering if there any options to reproduce range operator. I still would like to rely on C++/prprocessor framework exclusively. So far I have looked through boost wave which might be an suitable option. is there any other means to introduce new operators to C++ DSL?

    Read the article

  • Optimizing list comprehension to find pairs of co-prime numbers

    - by user3685422
    Given A,B print the number of pairs (a,b) such that GCD(a,b)=1 and 1<=a<=A and 1<=b<=B. Here is my answer: return len([(x,y) for x in range(1,A+1) for y in range(1,B+1) if gcd(x,y) == 1]) My answer works fine for small ranges but takes enough time if the range is increased. such as 1 <= A <= 10^5 1 <= B <= 10^5 is there a better way to write this or can this be optimized?

    Read the article

  • Reading Excel Named Ranges by OLEDB hangs when the source file is open

    - by Sathish
    I am trying to read the Excel Named range using OLEDB using the below code "Select * from [MyNamedRange1]" everything works fine only when the source excel sheet is not opened if it is open then i am not able to read the range names using OLEDB it simply hangs Where as i am able to execute the query "Select * from [Sheet1$]" even if the workbook is open or closed... Any work arounds for reading the range by OLEDB only i dont want to go for interop... I have too many ranges defined in the excel file

    Read the article

  • python-McNuggets

    - by challarao
    I have created some program for this.But printed a,b,c values are not correct.Please check this weather it is correct or not? n=input("Enter the no.of McNuggets:") a,b,c=0,0,0 count=0 for a in range(n): if 6*a+9*b+20*c==n: count=count+1 break else: for b in range(n): if 6*a+9*b+20*c==n: count=count+1 break else: for c in range(n): if 6*a+9*b+20*c==n: count=count+1 break if count>0: print "It is possible to buy exactly",n,"packs of McNuggetss",a,b,c else: print "It is not possible to buy"

    Read the article

  • Initializing a C++ vector to random values... fast

    - by Flamewires
    Hey, id like to make this as fast as possible because it gets called A LOT in a program i'm writing, so is there any faster way to initialize a C++ vector to random values than: double range;//set to the range of a particular function i want to evaluate. std::vector<double> x(30, 0.0); for (int i=0;i<x.size();i++) { x.at(i) = (rand()/(double)RAND_MAX)*range; } EDIT:Fixed x's initializer.

    Read the article

  • removing elements incrementally from a list

    - by Javier
    Dear all, I've a list of float numbers and I would like to delete incrementally a set of elements in a given range of indexes, sth. like: for j in range(beginIndex, endIndex+1): print ("remove [%d] => val: %g" % (j, myList[j])) del myList[j] However, since I'm iterating over the same list, the indexes (range) are not valid any more for the new list. Does anybody has some suggestions on how to delete the elements properly? Best wishes

    Read the article

  • How can I make an aggregated property support ActiveRecord::Dirty semantics?

    - by Eric
    I have an aggregated attribute which I want to be able ask about its _changed? ness, etc. composed_of :range, :class_name => 'Range', :mapping => [ %w(range_begin begin), %w(range_end end)], :allow_nil => true If I use the aggregation: foo.range = 1..10 This is what I get: foo.range # => 1..10 foo.range_changed? # NoMethodError foo.range_was # ditto foo.changed # ['range_begin', 'range_end'] So basically, I'm not getting ActiveRecord::Dirty semanitcs on aggregated attributes. Is there any way to do that? I'm not having a lot of luck with alias_attribute_with_dirty, etc.

    Read the article

  • How to have an excel addin read rows from a worksheet until no more data?

    - by user169867
    I've started writing a Com addin for Excel 2003 using C#. I'm looking for a code example showing how to read in cell data from the active worksheet. I've seen that you can write code like this: Excel.Range firstCell = ws.get_Range("A1", Type.Missing); Excel.Range lastCell = ws.get_Range("A10", Type.Missing); Excel.Range worksheetCells = ws.get_Range(firstCell, lastCell); to grab a range of cells. What I could use help with is how to read the cell data when you don't know how many rows of data there are. I may be able to determine the starting row that the data will be begin at, but there will be an unkown number of rows of data to read. Could someone provide me w/ an example of how to read rows from the worksheet until you come across a row of empty cells? Also does anyone know how to grab the range of cells the user has selected? Any help would be greatly appreciated. This seems like a powerful dev tool, but I'm having trouble finding detailed documentation to help me learn it :)

    Read the article

  • Python. Draw rectangle in basemap

    - by user2928318
    I need to add several rectangles in my basemap. I nee four rectangles with lat and log ranges as below. 1) llcrnrlon=-10, urcrnrlon=10, llcrnrlat=35,urcrnrlat=60 2) llcrnrlon=10.5, urcrnrlon=35, llcrnrlat=35,urcrnrlat=60 3) llcrnrlon=35.5, urcrnrlon=52, llcrnrlat=30,urcrnrlat=55 4) llcrnrlon=-20, urcrnrlon=35, llcrnrlat=20,urcrnrlat=34.5 My script is below. I found "polygon" packages to add lines but I do not exactly know how to do. Please help me!! Thanks a lot for your help in advance! from mpl_toolkits.basemap import Basemap m=basemaputpart.Basemap(llcrnrlon=-60, llcrnrlat=20, urcrnrlon=60, urcrnrlat=70, resolution='i', projection='cyl', lon_0=0, lat_0=45) lon1=np.array([[-180.+j*0.5 for j in range(721)] for i in range(181)]) lat1=np.array([[i*0.5 for j in range(721)] for i in range(181) ]) Nx1,Ny1=m(lon1,lat1,inverse=False) toplot=data[:,:] toplot[data==0]=np.nan toplot=np.ma.masked_invalid(toplot) plt.pcolor(Nx1,Ny1,np.log(toplot),vmin=0, vmax=5) cbar=plt.colorbar() m.drawcoastlines(zorder=2) m.drawcountries(zorder=2) plt.show()

    Read the article

  • need help me in excel-vba

    - by aos
    Private Sub cmdClear_Click() Dim Confirm As Integer Confirm = MsgBox("Are you sure you want clear this Sheet?", vbYesNo, "WARNING: Date Changed") If Confirm = 6 Then Sheets("OPV").Activate 'Sheets("OPV").Activate Sheets("OPV").Range("B4:BZ1000").ClearContents Sheets("OPV").Range("B4:BZ1000").Interior.Pattern = xlNone Sheets("OPV").Activate Sheets("OPV").Range("B4").Activate MsgBox " Done .. ", vbInformation, "Clear ......" End If End Sub

    Read the article

  • How can I identify an element from a list within another list

    - by Alex
    I have been trying to make a block of code that finds the index of the largest bid for each item. Then I was going to use the index as a way to identify the person who paid that much moneys name. However no matter what i try I can't link the person and what they have gained from the auction together. Here is the code I have been writing: It has to be able to work with any information inputted def sealedBids(): n = int(input('\nHow many people are in the group? ')) z = 0 g = [] s = [] b = [] f = [] w = []#goes by number of items q = [] while z < n: b.append([]) z = z + 1 z = 0 while z < n: g.append(input('Enter a bidders name: ')) z = z + 1 z = 0 i = int(input('How many items are being bid on?')) while z < i: s.append(input('Enter the name of an item: ')) w.append(z) z = z + 1 z = 0 for j in range(n):#specifies which persons bids your taking for k in range(i):#specifies which item is being bid on b[j].append(int(input('How much money has {0} bid on the {1}? '.format(g[j], s[k])))) print(' ') for j in range(n):#calculates fair share f.append(sum(b[j])/n) for j in range(i):#identifies which quantity of money was the largest for each item for k in range(n): if w[j] < b[k][j]: w[j] = b[k][j] q.append(k) any advice is much appreciated.

    Read the article

  • How to generate a random BigInteger value in Java?

    - by Bill the Lizard
    I need to generate arbitrarily large random integers in the range 0 (inclusive) to n (exclusive). My initial thought was to call nextDouble and multiply by n, but once n gets to be larger than 253, the results would no longer be uniformly distributed. BigInteger has the following constructor available: public BigInteger(int numBits, Random rnd) Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2numBits - 1), inclusive. How can this be used to get a random value in the range 0 - n, where n is not a power of 2?

    Read the article

  • Validation for textfield is not working

    - by MaheshBabu
    Hi folks, I am using 4 Textfields in my application. I need to validate those textfields like,These 4 textfields Allow only o,1,....9 and . For that i use the code like this. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { static NSCharacterSet *charSet = nil; if(!charSet) { charSet = [[[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet] retain]; } NSRange location = [string rangeOfCharacterFromSet:charSet]; return (location.location == NSNotFound); And first textfield allows digits 10,second third and fourth textfields allows less than 100. For that my code is if (textField.tag == 1) { NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; double homevaluedouble = [newString doubleValue]; return !(homevaluedouble > 10000000000); } if (textField.tag == 2) { NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; double validate = [newString doubleValue]; return !(validate > 100); } if (textField.tag == 3) { NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; double validate = [newString doubleValue]; return !(validate > 100); } I write this code in - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { But textfields allows 0,1,..9 and . but digit limit is not working, if i remove 0,1,...9 then limit to textfield working. i am getting confuse with it. can any one pls help me,How can i resolve it. Thank u in advance.

    Read the article

  • Automaically select the lastrow in PivotTable SourceData to avoid (blanks)

    - by Adam
    Hi A little help needed, I have a Macro automatically creating pivot tables and charts, this is all working fine but I am getting (blank) in my pivot table becuase my range is all the way to 65536. How do I automatically get the lastrow / column in my source data so I dont get any blanks. The data is changing constantly so this needs to be automatic Here is the source data, I am looking to get the R65536C37 to be automatically generated based on the lastcolumn of the "raw" sheet ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _ "raw!R1C1:R65536C37").CreatePivotTable _ TableDestination:="Frontpage!R7C1", TableName:="PivotTable2", _ DefaultVersion:=xlPivotTableVersion10 I have tried; LastRow = ActiveSheet.UsedRange.Rows.Count SourceData:= "raw!R1C1:" & LastRow & C37" Pivot Macro Sheets("Frontpage").Select Range("A7").Select ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _ "raw!R1C1:R65536C37").CreatePivotTable _ TableDestination:="Frontpage!R7C1", TableName:="PivotTable2", _ DefaultVersion:=xlPivotTableVersion10 Sheets("Frontpage").Select Cells(7, 1).Select ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=Range("Frontpage!$A$7:$H$22") ActiveChart.ChartType = xlColumnClustered With ActiveSheet.PivotTables("PivotTable2").PivotFields("Priority") .Orientation = xlRowField .Position = 1 End With ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _ "PivotTable2").PivotFields("Case ID"), "Count of Case ID", xlCount ActiveChart.Parent.Name = "IncidentsbyPriority" ActiveChart.ChartTitle.Text = "Incidents by Priority" Dim RngToCover As Range Dim ChtOb As ChartObject Set RngToCover = ActiveSheet.Range("D7:L16") Set ChtOb = ActiveSheet.ChartObjects("IncidentsbyPriority") ChtOb.Height = RngToCover.Height ' resize ChtOb.Width = RngToCover.Width ' resize ChtOb.Top = RngToCover.Top ' reposition ChtOb.Left = RngToCover.Left ' reposition Any help would be greatly appreciated. I need to repeat this in four other pivots so as to avoid getting (blank) in my tables and charts.

    Read the article

< Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >