Search Results

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

Page 56/199 | < Previous Page | 52 53 54 55 56 57 58 59 60 61 62 63  | Next Page >

  • Calculating the union of 2 longitudal intervals (that may wrap around 180 degrees)

    - by timpatt
    The story: I have a LatLongBounds class that represents an area on the surface of the earth by a latitudinal interval (bounded by north & south - not important to this question) and a longitudinal interval (bounded by east and west; both normalized to a range [-180, 180] - negative being a westerly direction). In order to be able to represent an area that straddles the 180 degree meridian the value of west may be set to be greater than east (eg. the range west = 170, east = -170 will straddle said meridian). In effect the longitudinal interval may wrap around at 180 degrees (or equivalently -180 degrees). My Question: Does anyone have any suggestions as to how I can calculate the union of two longitudinal intervals that may wrap around at 180 degrees. Thanks.

    Read the article

  • How Do I Search Between a Date Rang Using the ActiveRecord Model?

    - by Russ Bradberry
    I am new to both Ruby and ActiveRecord. I currently have a need to modify and existing piece of code to add a date range in the select. The current piece goes like this: ReportsThirdparty.find(:all, :conditions => {:site_id=>site_id, :campaign_id=>campaign_id, :size_id=>size_id}) Now, I need to add a range, but I am not sure how to do the BETWEEN or >= or <= operators. I guess what I need is something similar to: ReportsThirdparty.find(:all, :conditions => {:site_id=>site_id, :campaign_id=>campaign_id, :size_id=>size_id, :row_date=>"BETWEEN #{start_date} AND #{end_date}") Even if this did work, I know that using interpolation here would leave me subject to SQL injection attacks.

    Read the article

  • Multiprocessing Bomb

    - by iKarampa
    I was working the following example from Doug Hellmann tutorial on multiprocessing: import multiprocessing def worker(): """worker function""" print 'Worker' return if __name__ == '__main__': jobs = [] for i in range(5): p = multiprocessing.Process(target=worker) jobs.append(p) p.start() When I tried to run it outside the if statement: import multiprocessing def worker(): """worker function""" print 'Worker' jobs = [] for i in range(5): p = multiprocessing.Process(target=worker) jobs.append(p) p.start() It started spawning processes non-stop, without any way of to terminating it. Why would that happen? Why it did not generate 5 processes and exit? Why do I need the if statement?

    Read the article

  • Multiplying matrices: error: expected primary-expression before 'struct'

    - by justin
    I am trying to write a program that is supposed to multiply matrices using threads. I am supposed to fill the matrices using random numbers in a thread. I am compiling in g++ and using PTHREADS. I have also created a struct to pass the data from my command line input to the thread so it can generate the matrix of random numbers. The sizes of the two matrices are also passed in the command line as well. I keep getting: main.cpp:7: error: expected primary-expression before 'struct' my code @ line 7 =: struct a{ int Arow; int Acol; int low; int high; }; My inpust are : Sizes of two matrices ( 4 arguments) high and low ranges in which o generate the random numbers between. Complete code: [headers] using namespace std; void *matrixACreate(struct *); void *status; int main(int argc, char * argv[]) { int Arow = atoi(argv[1]); // Matrix A int Acol = atoi(argv[2]); // WxX int Brow = atoi(argv[3]); // Matrix B int Bcol = atoi(argv[4]); // XxZ, int low = atoi(argv[5]); // Range low int high = atoi(argv[6]); struct a{ int Arow; // Matrix A int Acol; // WxX int low; // Range low int high; }; pthread_t matrixAthread; //pthread_t matrixBthread; pthread_t runner; int error, retValue; if (Acol != Brow) { cout << " This matrix cannot be multiplied. FAIL" << endl; return 0; } error = pthread_create(&matrixAthread, NULL, matrixACreate, struct *a); //error = pthread_create(&matrixAthread, NULL, matrixBCreate, sendB); retValue = pthread_join(matrixAthread, &status); //retValue = pthread_join(matrixBthread, &status); return 0; } void matrixACreate(struct * a) { struct a *data = (struct a *) malloc(sizeof(struct a)); data->Arow = Arow; data->Acol = Acol; data->low = low; data->high = high; int range = ((high - low) + 1); cout << Arow << endl<< Acol << endl; }// just trying to print to see if I am in the thread

    Read the article

  • Loop colours from variables for graphics.py [Python 3.2]

    - by user1056548
    I am creating a graphics program that draws 100 x 100 squares next to each other depending on the user-specified grid size. The user also inputs 4 colours for the squares to be coloured (e.g. if they enter red,green,blue,yellow the squares will be coloured in that order, repeating the colours). Is it possible to loop the colours from the variables the user has given? Here is what I have so far: def main(): print ("Please enter four comma seperated colours e.g.: 'red,green,blue,yellow'\n\ Allowed colours are: red, green, blue, yellow and cyan") col1, col2, col3, col4 = input("Enter your four colours: ").split(',') win = GraphWin ("Squares", 500, 500) colours = [col1, col2, col3, col4] drawSquare (win, col1, col2, col3, col4, colours) win.getMouse() win.close() def drawSquare(win, col1, col2, col3, col4, colours): for i in range (4): for j in range (len(colours)): colour = colours[j] x = 50 + (i * 50) circle = Circle (Point (x,50), 20) circle.setFill(colour) circle.draw(win) I think I should be using a list in some way, but can't work out exactly how to do it. Can anybody help?

    Read the article

  • how to get day name in datetime in python

    - by gadss
    how can I get the day name (such as : Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday) in datetime in python?... here is my code in my handlers.py from django.utils.xmlutils import SimplerXMLGenerator from piston.handler import BaseHandler from booking.models import * from django.db.models import * from piston.utils import rc, require_mime, require_extended, validate import datetime class BookingHandler(BaseHandler): allowed_method = ('GET', 'POST', 'PUT', 'DELETE') fields = ('id', 'date_select', 'product_name', 'quantity', 'price','totalcost', 'first_name', 'last_name', 'contact', 'product') model = Booking def read(self, request, id, date_select): if not self.has_model(): return rc.NOT_IMPLEMENTED try: prod = Product.objects.get(id=id) prod_quantity = prod.quantity merge = [] checkDateExist = Booking.objects.filter(date_select=date_select) if checkDateExist.exists(): entered_date = Booking.objects.values('date_select').distinct('date_select').filter(date_select=date_select)[0]['date_select'] else: entered_date = datetime.datetime.strptime(date_select, '%Y-%m-%d') entered_date = entered_date.date() delta = datetime.timedelta(days=3) target_date = entered_date - delta day = 1 for x in range(0,7): delta = datetime.timedelta(days=x+day) new_date = target_date + delta maximumProdQuantity = prod.quantity quantityReserve = Booking.objects.filter(date_select=new_date, product=prod).aggregate(Sum('quantity'))['quantity__sum'] if quantityReserve == None: quantityReserve = 0 quantityAvailable = prod_quantity - quantityReserve data1 = {'maximum_guest': maximumProdQuantity, 'available': quantityAvailable, 'date': new_date} merge.append(data1) return merge except self.model.DoesNotExist: return rc.NOT_HERE in my code: this line sets the date: for x in range(0,7): delta = datetime.timedelta(days=x+day) new_date = target_date + delta

    Read the article

  • Suggestion for creating custom sound recognition software to toggle audio

    - by Parrot owner
    I need to develop a program that toggles a particular audio track on or off when it recognizes a parrot scream or screech. The software would need to recognize a particular range of sounds and allow some variations in the range (as a parrot likely won't replicate its sreeches EXACTLY each time). Example: Bird screeches, no audio. Bird stops screeching for five seconds, audio track praising the bird plays. Regular chattering needs to be ignored completely, as it is not to be discouraged. I've heard of java libraries that have speech recognition with dictionaries built in, but the software would need to be taught the particular sounds that my particular parrot makes - not words or any random bird sound. In addition as I mentioned above, it would need to allow for slight variation in the sound, as the screech will likely never be 100% identical to the recorded version. What would be the best way to go about this/what language should I look into?

    Read the article

  • Translate imperative control flow with break-s/continue-s to haskell

    - by dorserg
    Consider the following imperative code which finds the largest palindrome among products of 3-digit numbers (yes, it's the one of the first tasks from "Project of [outstanding mathematician of 18th century]" site): curmax = 0 for i in range(999,100): for j in range(999,100): if ((i*j) < curmax): break if (pal(i*j)): curmax = i*j break print curmax As I'm learning Haskell currently, my question is, how do you translate this (and basically any imperative construct that contains something more complex than just plain iteration, e.g. breaks, continues, temporary variables and all this) to Haskell? My version is maxpal i curmax | i < 100 = curmax | otherwise = maxpal (i-1) (innerloop 999) where innerloop j | (j < 100) || (p < curmax) = curmax | pal p = p | otherwise = innerloop (j-1) where p = i*j main = print $ maxpal 999 0 but this looks like we're still in imperative uglytown. So what could you advise, what are the approaches of dealing with such cases FP-style?

    Read the article

  • What's the correct way to hide/prevent access to wp-admin

    - by Jaypee
    I'm dealing with this matter since a while, I have read a ton of articles and stuff out there but I couldn't find a place that shows the RIGHT way, standard, correct, whatever you like to call it, to prevent access to my wp-admin or wp-login.php On all Wordpress sites I see (the well made ones) you will never see anything if you type thesite.com/wp-admin As I could see, one way to do this is by restricting the access to that folder by creating an .htaccess file and restrict by IP the access to the folder. Seems to be the "cleanest" way to do. What I'm not sure about it is that I have a dynamic address provided by my ISP, so on a certain time my IP will change, that will force me to also change the .htaccess to my new address, I don't see that practical. I can set a range also, but by doing that I will also authorize access to all people within that range of IPs (other clients of my ISP for example). I'm then struggling to find the best/standard way to do this. Anyone can help me? Thanks

    Read the article

  • Reintegrate a branch with externals fails in SVN

    - by dnndeveloper
    What I am doing: Apply external properties to a folder in the trunk (both single file and folder external, externals are binary files) Create a branch from the trunk and update the entire project Modify a file on the branch and commit the changes, then update the entire project. Merge - "Reintegrate a branch" when I get to the last screen I click "test merge" and get this error: Error: Cannot reintegrate into mixed-revision working copy; try updating first I update the entire project and still the same error. Other observations: If I "Merge a range of revisions" everything works fine. If I remove the externals everything works fine using either "Merge a range of revisions" or "Reintegrate a branch". How do I solve this issue? I am using Subversion 1.6.6 with TortoiseSVN 1.6.6.

    Read the article

  • Switch to BigInteger if necessary

    - by fahdshariff
    I am reading a text file which contains numbers in the range [1, 10^100]. I am then performing a sequence of arithmetic operations on each number. I would like to use a BigInteger only if the number is out of the int/long range. One approach would be to count how many digits there are in the string and switch to BigInteger if there are too many. Otherwise I'd just use primitive arithmetic as it is faster. Is there a better way? Is there any reason why Java could not do this automatically i.e. switch to BigInteger if an int was too small? This way we would not have to worry about overflows.

    Read the article

  • compute mean in python for a generator

    - by nmaxwell
    Hi, I'm doing some statistics work, I have a (large) collection of random numbers to compute the mean of, I'd like to work with generators, because I just need to compute the mean, so I don't need to store the numbers. The problem is that numpy.mean breaks if you pass it a generator. I can write a simple function to do what I want, but I'm wondering if there's a proper, built-in way to do this? It would be nice if I could say "sum(values)/len(values)", but len doesn't work for genetators, and sum already consumed values. here's an example: import numpy def my_mean(values): n = 0 Sum = 0.0 try: while True: Sum += next(values) n += 1 except StopIteration: pass return float(Sum)/n X = [k for k in range(1,7)] Y = (k for k in range(1,7)) print numpy.mean(X) print my_mean(Y) these both give the same, correct, answer, buy my_mean doesn't work for lists, and numpy.mean doesn't work for generators. I really like the idea of working with generators, but details like this seem to spoil things. thanks for any help -nick

    Read the article

  • MYSQL - multiple count statments

    - by darudude
    I'm trying to do a lookup on our demographioc table to display some stats. However, since out demographic table is quit big I want to do it in one query. There are 2 fields that are important: sex, last_login I want to be able to get the total number of logins for various date ranges (<1day ago, 1-7 days ago, 7-30 days ago, etc) GROUPED BY sex I right now know how to do it for one date range. For example less than 1 day ago: SELECT sex, count(*) peeps FROM player_account_demo WHERE last_demo_update>1275868800 GROUP BY sex Which returns: sex peeps UNKNOWN 22 MALE 43 FEMALE 86 However I'd have to do this once for each range. Is there a way to get all 3 ranges in there? I'd want my end result to look something like this: sex peeps<1day peeps1-7days peeps7-30days Thanks!

    Read the article

  • How do I request a single random row from a force.com database in SOQL?

    - by Ollie C
    Total row-count is in the range 10k-100k rows. Can I use RAND() on force.com? Unfortunately although all the rows have a unique numeric identifier, there are many gaps, and I'd often want to select a random row from a filtered subset anyway. I suspect there's no particularly efficient way to do this, but is it possible at all? Ultimately all I want to do is to extract one row from a table (or a subset based on specific filter criteria) at random. If force.com doesn't let me select a random row, then can I query the rows to select from, and assign sequential IDs to all the rows, say 1-1,035, and then select a random number in that range locally, say 349, and then get row 349?

    Read the article

  • merging selected revisions from one branch on another in Mercurial

    - by Assaf Lavie
    Is it possible to merge a range of revisions from one branch to another in Mercurial? e.g. |r1 |r2 |r3 |\___ | | r5 | | r6 | | r7 | | ... | | r40 |r41 If I want to merge revisions 6 & 7, but not 5, into the main branch - is this possible? What about multiple selected revision ranges from branch A to branch B? e.g. merge 4-7, 20-25 and 30-34? (this isn't a real case, just an illustration. I'm trying to understand if hg has this revision-range merge feature that I know svn has)

    Read the article

  • Random List of millions of elements in Python Efficiently

    - by eWizardII
    Hello, I have read this answer potentially as the best way to randomize a list of strings in Python. I'm just wondering then if that's the most efficient way to do it because I have a list of about 30 million elements via the following code: import json from sets import Set from random import shuffle a = [] for i in range(0,193): json_data = open("C:/Twitter/user/user_" + str(i) + ".json") data = json.load(json_data) for j in range(0,len(data)): a.append(data[j]['su']) new = list(Set(a)) print "Cleaned length is: " + str(len(new)) ## Take Cleaned List and Randomize it for Analysis shuffle(new) If there is a more efficient way to do it, I'd greatly appreciate any advice on how to do it. Thanks,

    Read the article

  • SQL query to get field value distribution

    - by Bryan Lewis
    I have a table of over 1 million test score records that basically have a unique score_ID, a subject_ID and a score given by a person. The score range for most subjects is 0-3, but some have a range of 0-4. There are about 25 possible subjects. I need to produce a score distribution report which looks like: subject_ID 0 1 2 3 4 ---------- --- --- --- --- --- 1 967 576 856 234 2 576 947 847 987 324 . . So it groups the data by subject_ID, then shows how many times a specific score value was given within that subject. Any SQL pointers to generate this would be greatly appreciated.

    Read the article

  • Random access view in boost::multi_array

    - by linai
    Here is a boost example: typedef boost::multi_array<double, 1> array_type; typedef array_type::index index; array_type A(boost::extents[100]); for(index i = 0; i != A.size(); ++i) { A[i] = (double)i; } // creating view array_type::index_gen indices; typedef boost::multi_array_types::index_range range; array_type::array_view<1>::type myview = A[ indices[range(0,50)] ]; What this code does is creating a subarray or view mapping onto the original array. This view is continuous and covers from 0th to 50th elements of an original array. What if I need to explicitly define elements I'd like to see in the view? How can I create a view with indices like [1, 5, 35, 23] ? Any ideas?

    Read the article

  • A RAM error of big array

    - by flint
    I have a big file, more than 400M. In that file, there are 13496*13496 number, means 13496 rows and 13496 cols. I want to read them to a array. This is my code: _L1 = [[0 for col in range(13496)] for row in range(13496)] _L1file = open('distanceCMD.function.txt') while (i<13496): print "i="+str(i) _strlf = _L1file.readline() _strlf = _strlf.split('\t') _strlf = _strlf[:-1] _L1[i] = _strlf i += 1 _L1file.close() And this is my error massage: MemoryError: File "D:\research\space-function\ART3.py", line 30, in <module> _strlf = _strlf.split('\t')

    Read the article

  • VBA: How to trigger a worksheet event function by an automatic cell change trough a link?

    - by Jesse
    Hi, My problem is the following: The function below triggers an "if then function" when i manually change the value in cell D9. What should I do to get it to work with an automatic value change of cell D9 trough a link. In other words if i where to link cell D9 to cell A1 and change the value of A1 can i still make the function below work? Thanks in advance Private Sub Worksheet_Change(ByVal Target As range) If Target.Address = "$D$9" Then If range("C12") = 0 Then Rows("12:12").Select Selection.RowHeight = 0 Else: Rows("12:12").Select Selection.RowHeight = 15 End If End Sub

    Read the article

  • syntax to express mathematical formula concisely in your language of choice

    - by aaa
    hello. I am developing functional domain specific embedded language within C++ to translate formulas into working code as concisely and accurately as possible. Right now my language looks something like this: // implies two nested loops j=0:N, i=0,j (range(i) < j < N)[T(i,j) = (T(i,j) - T(j,i))/e(i+j)]; // implies summation over above expression sum(range(i) < j < N))[(T(i,j) - T(j,i))/e(i+j)]; I am looking for possible syntax improvements/extensions or just different ideas about expressing mathematical formulas as clearly and precisely as possible. Can you give me some syntax examples relating to my question which can be accomplished in your language of choice which consider useful. In particular, if you have some ideas about how to translate the above code segments, I would be happy to hear them Thank you

    Read the article

  • find a duplicate entry in an array in constant space and O(n) time [closed]

    - by Anubhav Agarwal
    Possible Duplicate: Algorithm to find a duplicate entry in constant space and O(n) time Given an array of N integer such that only one integer is repeated. Find the repeated integer in O(n) time and constant space. There is no range for the value of integers or the value of N For example given an array of 6 integers as 23 45 67 87 23 47. The answer is 23 (I hope this covers ambiguous and vague part) I searched on the net but was unable to find any such question in which range of integers was not fixed. Also here is an example that answers a similar question to mine but here he created a hash table with the highest integer value in C++.But the cpp does not allow such to create an array with 2^64 element(on a 64-bit computer).

    Read the article

  • Alternative to nesting for loops in Python

    - by davenz
    I've read that one of the key beliefs of Python is that flat nested. However, if I have several variables counting up, what is the alternative to multiple for loops? My code is for counting grid sums and goes as follows: def horizontal(): for x in range(20): for y in range(17): temp = grid[x][y: y + 4] sum = 1 for n in temp: sum += int(n) return sum This seems to me like it is too heavily nested. Firstly, what is considered to many nested loops in Python ( I have certainly seen 2 nested loops before). Secondly, if this is too heavily nested, what is an alternative way to write this code?

    Read the article

  • Counts of events grouped by date in python?

    - by Sologoub
    This is no doubt another noobish question, but I'll ask it anyways: I have a data set of events with exact datetime in UTC. I'd like to create a line chart showing total number of events by day (date) in the specified date range. Right now I can retrieve the total data set for the needed date range, but then I need to go through it and count up for each date. The app is running on google app engine and is using python. What is the best way to create a new data set showing date and corresponding counts (including if there were no events on that date) that I can then use to pass this info to a django template? Data set for this example looks like this: class Event(db.Model): event_name = db.StringProperty() doe = db.DateTimeProperty() dlu = db.DateTimeProperty() user = db.UserProperty() Ideally, I want something with date and count for that date. Thanks and please let me know if something else is needed to answer this question!

    Read the article

< Previous Page | 52 53 54 55 56 57 58 59 60 61 62 63  | Next Page >