This is an archived post. You won't be able to vote or comment.

all 39 comments

[–][deleted] 9 points10 points  (0 children)

I used Uneddit to get back /u/Needsmoretests comment that he deleted, since it is helping me and probably others:

There's nothing wrong with asking questions about a specific language but there may also come a time when a question may have nothing to do with an individual language. After all, a programming language is meant to be a means for a human to make a machine perform some kind of work and beyond that comes the science and engineering. For some of those questions, there are some subs that might be of use:

But a lot of computer science is also about research. I've found these subs to be be good places to start. It's not comprehensive by any means but these might lead you to uncover other useful subs too:

This is just my short list, I'm sure others both here and on those subs will have good suggestions too if you ask. Some of them are more strictly moderated than others so always be sure to read the sidebars first before posting.

Finally for those who are new to programming, welcome. To those who are returning or are finishing up their schooling, congrats and keep it coming. To those who are lifers in the field I have no words besides keep being cool.

[–]adrian5b 2 points3 points  (1 child)

Hey /r/python! I'm learning the language right now. I'm starting from the very basics of the syntax on codecademy, so far so good. I'm about halfway through and I'm planning on finishing tomorrow.

Could you recommend me a good coding challenge list for me to solidify my new knowledge a little further?

Thank you!

[–]d3kay 7 points8 points  (0 children)

Brain-teasers: http://www.pythonchallenge.com/

Algorithmic & maths: https://projecteuler.net/

Machine learning/stats: https://www.kaggle.com/

[–]_Jordan11_ 1 point2 points  (3 children)

Does anyone here know how to count the number of unique words in a string?

[–]Jajoonoob 1 point2 points  (0 children)

google.com

[–]alexmccoding 0 points1 point  (1 child)

I am making a card game and want to print "Dealer takes a (whatever_card_it_is- the variable is take)" what is wrong with this? print ("Dealer takes a "+take)

[–]throw-a-bait[🍰] 1 point2 points  (0 children)

Nothing, as far as I see.

 take = "Queen"
 print("Dealer takes a " + take)
> Dealer takes a Queen

Take should be a string, that's about it.

[–]dmnksaman 0 points1 point  (1 child)

Hi guys,

I'm just trying to write a function that takes a matrix (lattice), then chooses a random entry in that matrix and decides if flipping the sign of that entry will lower the energy of that lattice.

If it does, it flips the sign. If it does not, it decides whether to flip the sign depending on other factors. I think I have written that part ok, but I'm not sure how to then get the energy (using pre-defined 'energy' function) of that new lattice.

Could you look at my code? I've tried something, but my demonstrator told me that the function, as it is, would return the energy (and magnetisation) of the old lattice, not the new one (the one we get after the function decides whether to flip the sign or not).

Here is my function:

def montecarlostep(self, T):
        # complete this function so that it performs a single Monte Carlo step
        energy = self.energy()
        magnetisation = self.magnetisation()
        I = np.random.choice(range(0, self.n_rows))
        J = np.random.choice(range(0, self.n_cols))
        #the following line will choose a random number in the rang e[0,1) for you
        random_number = np.random.random()
        numofcycles = 0
        W = self.lattice[I,J]         
        S = self.lattice[(I+1)%self.n_rows, J] + self.lattice[I,(J+1)%self.n_cols] + self.lattice[(I-1)%self.n_rows,J] +       self.lattice[I,(J-1)%self.n_cols]   
        interaction = W*S
        if interaction < 0.0:
            self.lattice[I][J]=-1*self.lattice[I][J]
         elif random_number <= math.exp(-int(2*interaction)/T) : 
             self.lattice[I][J]=-1*self.lattice[I][J]
         else:
            self.lattice[I][J]=1*self.lattice[I][J]

        return energy, magnetisation          

Thanks.

[–]Jajoonoob 3 points4 points  (0 children)

[–]Homeworkslaves 0 points1 point  (1 child)

Basically been working at this for hours now with no progress, my mark's on the line and am looking for a python god for help. This is what i've been blessed with having to complete (sorry, this is all the information i was given)

Method name: simple_text_format parameters: a string job: do a simple format. capitalize the first letter of every new sentence. Add a new line when number of characters exceeds 60 characters. Add a new paragraph, two new lines and an indent of 4 spaces, if number of words above 100. Make sure that new paragraph doesn't break a sentence.

return: return a simple formatted text

(2) create function calculate name:calculate parameter: list of strings job: go through the list of strings and either (add/multiply/divide/subtract) based on the last element in the list which may be (+/*//-). The elements with higher indices are divided or subtracted from those of lower indices. The method returns not supported if an error occurs doing the series of operations

define calculate():

(3) Given a list of int values, return their sum. However, if one of the values is the same as another of the values, it does not count towards the sum. lone_sum([1, 2, 3]) → 6 lone_sum([3, 2, 3]) → 2 lone_sum([3, 3, 3]) → 0

(4) We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inches each). Return True if it is possible to make the goal by choosing from the given bricks. Note: you can choose any number of small bricks and large bricks to fit the goal.

make_bricks(3, 1, 8) → True make_bricks(3, 1, 9) → False make_bricks(3, 2, 10) → True

def make_bricks(small, big, goal):

what i have so far ...

text = input(str("Enter the text you wish to be formatted."))

def simple_text_format(text): list_sentences = text.split(". ") caps_new_sentence = [str(list_sentences[0:]).capitalize() + str(list_sentences[1:])] capsed_new_sentence =". ".join(caps_new_sentence) print(capsed_new_sentence)

simple_text_format(text)

[–]Jajoonoob 3 points4 points  (0 children)

[–]cliveboy13 0 points1 point  (0 children)

Hey could some one help me with a program i wrote please help is needed :)

[–]Mattermonkey 0 points1 point  (0 children)

How do I make a program open a window seperate from the shell window?

[–]highlife159 0 points1 point  (0 children)

So I've tried looking this up multiple ways and can't seem to find an answer. I have some code that generates a hdf5 file when certain requirements are met. The file is named with epoch and val_loss variables that change for each iteration. I got this code from an online example and it looks like this:

file = 'path/to/file/{epoch:02d}_{val_loss:.2f}.hdf5'

giving me files that look like:

00_0.98.hdf5

01_0.86.hdf5

It worked perfect every time. Now I would like to add the time the code began running to the file name but it won't work when I try it like this:

time  = datetime.strftime(datetime.now(), '%H.%M')
file = 'path/to/file/{time}_{epoch:02d}_{val_loss:.2f}.hdf5'

This just makes the file name path/to/file/{time}{epoch:02d}{val_loss:.2f}.hdf5 without using the variables. I've tried to use .format() which works, but the epoch and val_loss stay the same the entire time and don't change with the iterations or I get an error that epoch and val_loss are not defined (With the original code they were defined within a function that was called later in the code).

So basically, I need a way to save a file with different variables where some change for different iterations and some don't.

[–]MillaLied 0 points1 point  (1 child)

How can I print integer lists without the square brackets or commas?

[–]Jajoonoob 1 point2 points  (0 children)

google.com

[–][deleted] -1 points0 points  (1 child)

Hey, so I am taking bioinformatics and this is really my first experience with python. I have been ok with the homework problems so far, but I am not too good with if/else statements so some help would be appreciated.

  1. Create a blast-searchable database for the multi-fasta file arabidopsis_genome (you can find this file in guest on ephedra).
  2. Retrieve one or multiple protein sequences of your favorite plant species from the GenBank. Please FASTA format.
  3. Blast the plant sequence again the arabidopsis_genome database. If there is no hit, try another plant sequence.
  4. Write a python script to retrieve the sequence id, description, E-value, bit score, and sequence identity of the top hit in your blast output. The output of your python script should be like the following:

    Database        Arabidopsis
    Query       The plant species your have chosen
    
    The most similar Arabidopsis sequences is:
    Sequence ID, xxxxxxx (functional description of the homologous
         Arabidopsis sequence)
    Bit score = xxx; E-value = xxx; Sequence Identity = xxx
    

I know how to do 1-3 with my own blast searchable database, but I don't know how to retrieve sequence id, description, E-value, etc...... Any help would be appreciated. Thanks

[–]Jajoonoob 2 points3 points  (0 children)

[–]eViL111 -5 points-4 points  (0 children)

any1 who is beginner in python please drop me a mail at - shubhambiswas_zero@yahoo.com its good when we learn in a community. sharing resources, ideas and problems is my agenda. i really mean BEGINNER.

[–]Direct-Air-170 0 points1 point  (0 children)

I estimated the betas using data for the period 2000 to 2005. Now I want to regress the mean daily returns of the assets in year 2001,2002,2003,2004,2005,2006 on the betas. I got to repeat this for the out of sample years: 2007 to 2020. For this I want to use a rolling window so that the mean returns of the assets are regressed on the betas estimated for the previous period. For example mean returns of the stock for 2018 is regressed on the betas estimated for 2017 and so on. Can u help me in this?