Hi folks,
I'm looking for a way to read in c++ a text file containing numpy arrays and put the data into vector , can anyone help me out please ?
Thanks a lot.
Archy
suppose I have a dictionary whose keys are strings. How can I efficiently make a new dictionary from that which contains only the keys present in some list?
for example:
# a dictionary mapping strings to stuff
mydict = {'quux': ...,
'bar': ...,
'foo': ...}
# list of keys to be selected from mydict
keys_to_select = ['foo', 'bar', ...]
The way I came up with is:
filtered_mydict = [mydict[k] for k in mydict.keys() \
if k in keys_to_select]
but I think this is highly inefficient because: (1) it requires enumerating the keys with keys(), (2) it requires looking up k in keys_to_select each time. at least one of these can be avoided, I would think. any ideas? I can use scipy/numpy too if needed.
I am hoping to write a script that will allow for the detection of video on a url and provide a download link to a *flv for google chrome.
Anyone have any suggestions were to start and get a footing?
I need to delete some unicode symbols from the string '?????? ??????? ???????????? ??????????'
I know they exist here for sure. I try:
re.sub('([\u064B-\u0652\u06D4\u0670\u0674\u06D5-\u06ED]+)', '', '?????? ??????? ???????????? ??????????')
but it doesn't work. String stays the same. ant suggestion what i do wrong?
I need to write a recursive function that can add two numbers (x, y), assuming y is not negative. I need to do it using two functions which return x-1 and x+1, and I can't use + or - anywhere in the code. I have no idea how to start, any hints?
def maxVote(nLabels):
count = {}
maxList = []
maxCount = 0
for nLabel in nLabels:
if nLabel in count:
count[nLabel] += 1
else:
count[nLabel] = 1
#Check if the count is max
if count[nLabel] > maxCount:
maxCount = count[nLabel]
maxList = [nLabel,]
elif count[nLabel]==maxCount:
maxList.append(nLabel)
return random.choice(maxList)
nLabels contains a list of integers.
The above function returns the integer with highest frequency, if more than one have same frequency then a randomly selected integer from them is returned.
E.g. maxVote([1,3,4,5,5,5,3,12,11]) is 5
I want to implement a code that loops inside an array that its size is set by the user that means that the size isn't constant.
for example:
A=[1,2,3,4,5]
then I want the output to be like this:
[1],[2],[3],[4],[5]
[1,2],[1,3],[1,4],[1,5]
[2,3],[2,4],[2,5]
[3,4],[3,5]
[4,5]
[1,2,3],[1,2,4],[1,2,5]
[1,3,4],[1,3,5]
and so on
[1,2,3,4],[1,2,3,5]
[2,3,4,5]
[1,2,3,4,5]
Can you help me implement this code?
I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:
list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
But if I run it my output looks like this:
>>> list1
[2, 4, 6]
>>> list2
[1, 3, 5]
My question is threefold, I guess: Why is this happening, how do I make it work, and am I overlooking an incredibly simple solution like a 'move' statement or something?
Greetings,
I am trying to bin an array of points (x, y) into an array of boxes [(x0, y0), (x1, y0), (x0, y1), (x1, y1)] (tuples are the corner points)
So far I have the following routine:
def isInside(self, point, x0, x1, y0, y1):
pr1 = getProduct(point, (x0, y0), (x1, y0))
if pr1 >= 0:
pr2 = getProduct(point, (x1, y0), (x1, y1))
if pr2 >= 0:
pr3 = getProduct(point, (x1, y1), (x0, y1))
if pr3 >= 0:
pr4 = getProduct(point, (x0, y1), (x0, y0))
if pr4 >= 0:
return True
return False
def getProduct(origin, pointA, pointB):
product = (pointA[0] - origin[0])*(pointB[1] - origin[1]) - (pointB[0] - origin[0])*(pointA[1] - origin[1])
return product
Is there any better way then point-by-point lookup? Maybe some not-obvious numpy routine?
Thank you!
import os
dictionaryfile = "/root/john.txt"
pgpencryptedfile = "helloworld.txt.gpg"
array = open(dictionaryfile).readlines()
for x in array:
x = x.rstrip('\n')
newstring = "echo " + x + " | gpg --passphrase-fd 0 " + pgpencryptedfile
os.popen(newstring)
I need to create something inside the for loop that will read gpg's output. When gpg outputs this string gpg: WARNING: message was not integrity protected, I need the loop to close and print Success!
How can I do this, and what is the reasoning behind it?
Thanks Everyone!
d3 = dict(d1, **d2)
I understand that this merges the dictionary. But, is it unique? What if d1 has the same key as d2 but different value? I would like d1 and d2 to be merged, but d1 has priority if there is duplicate key.
I can print a range of numbers easily using range, but is is possible to print a range with 1 decimal place from -10 to 10?
e.g
-10.0, -9.9, -9.8 all they way through to +10?
lst1 = ['one', 2, 3]
// What is the best way of the following -- or is there another way?
lst2 = list(lst1)
lst2 = lst1[:]
import copy
lst2 = copy.copy(lst1)
So I am trying to figure out how to post on a website that uses a drop down menu which is holding the values like this (based on the page source):
<td valign="top" align="right"><span class="emphasis">Select Item Option : </span></td>
<td align="left">
<span class="notranslate">
<select name="ItemOption1">
<option value="">Select Item Option</option>
<option value="321_cba">Item Option 1</option>
<option value="123_abcd">Item Option 2</option>
...
Now there are two of these drop down menus on top of each other. I want to be able to select an item from drop down menu 1 and drop down menu 2 and then submit the page. Now based on the code it submits the information using the following code:
<td colspan="2" align="center">
<input type="submit" value="View Result" onclick="return check()">
</td>
</tr>
</table>
<input type="hidden" name="ItemOption1" value="">
<input type="hidden" name="ItemOption2" value="">
I have no idea how to select the items in the drop down menu and then submit the page and capture the information on the resulting page into a text file. Can someone please help me with this?
I'm using Lucene to index components with names and types. Some components are more important, thus, get a bigger boost. However, I cannot get my boost to work properly. I sill get some components appear later (get worse score), even though they have a higher boost.
Note that the indexing is done on one field only and I've set the boost to that field alone. I'm using Lucene in Java.
I don't think it has anything to do with the field length. I've seen components with the same name (but different type) get the wrong score.
Hello Hackerz,
Here is the idea
A user can set a day alert for a birthday. (We do not care about the year of birth)
He also picks if he wants to be alerted 0, 1, 2, ou 7 days (Delta) before the D day.
Users have a timezone setting.
I want the server to send the alerts at 8 am on the the D day - deleta +- user timezone
Example:
12 jun, with "alert me 3 days before" will give 9 of Jun.
My idea was to have a trigger_datetime extra field saved on the 'recurrent event' object.
Like this a cron Job running every hour on my server will just check for all events matching irs current time hour, day and month and send to the alert.
The problem from a year to the next the trigger_date could change !
If the alert is set on 1st of March, with a one day delay that could be either 28 or 29 of February ..
Maybe i should not use the trigger date trick and use some other kind of scheme.
All plans are welcome.
I'm looking for a way for a function to take actions based on how long it has been executing. For example, my function would loop continuously until 5 seconds has elapsed, in which case it returns immediately. Any suggestions?
In this quicksort function:
def qsort2(list):
if list == []:
return []
else:
pivot = list[0]
# can't understand the following line
lesser, equal, greater = partition(list[1:], [], [pivot], [])
return qsort2(lesser) + equal + qsort2(greater)
def partition(list, l, e, g):
if list == []:
return (l, e, g)
else:
head = list[0]
if head < e[0]:
return partition(list[1:], l + [head], e, g)
elif head > e[0]:
return partition(list[1:], l, e, g + [head])
else:
return partition(list[1:], l, e + [head], g)
I don't understand the sentence below the comment. Can someone tell me what is the meaning of this sentence here?
Hi,
I have a list and a value and want to check if the value is not in the list.
list = [u'first record', u'second record']
value = 'first record'
if value not in list:
do something
however this is not working and I think it has something to do with the list values having a u at the start, how can I fix this? And before someone suggests the list is returned from Django queryset so I can't just take the u out of the code :)
Thanks
I have this for a for loop which I made I was wondering how I would write so it would work with a while loop.
def scrollList(myList):
negativeIndices=[]
for i in range(0,len(myList)):
if myList[i]<0:
negativeIndices.append(i)
return negativeIndices
So far I have this
def scrollList2(myList):
negativeIndices=[]
i= 0
length= len(myList)
while i != length:
if myList[i]<0:
negativeIndices.append(i)
i=i+1
return negativeIndices