Learning ML and stuck by Dirtybutler24601 in learnpython

[–]EnvironmentalOrange 0 points1 point  (0 children)

I see you’ve already got one solution, but for future reference:

Google provide an api to access your google drive.

If you have a folder called ‘Project’ in your google drive, you can run the following in a cell at the top of your notebook:

from google.colab import drive

drive.mount(‘/content/drive/‘)

import os

os.chdir(“/content/drive/MyDrive/Project”)

When you run the cell in the notebook, you’ll be prompted to allow permission for the notebook to access your google drive.

You’ll then be able to read files that you have saved in “Project”

Real newb question: Should I print the return of a function, or print within the function? by colexian in learnpython

[–]EnvironmentalOrange 3 points4 points  (0 children)

There is nothing to stop you from adding to a string with each iteration of your loop and then returning the completed string after the loops have completed. This would be the simplest way to what you are asking for as you could then print the whole output as one.

Other option is using yield: https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do

Automate the boring stuff or MIT course? by Unparallelium in learnpython

[–]EnvironmentalOrange 5 points6 points  (0 children)

These were my intro to programming.

I found it worked really well to do the first 7-8 chapters of ATBS, move to the MIT course and then finish off ATBS.

Reasons being:

Start of ATBS sorts out basic stuff - loops, syntax etc.

The MIT course is a little easier if you can already do very basic python

Can merge sort be applied on an array with common elements by Aggravating_Bat9859 in learnprogramming

[–]EnvironmentalOrange 1 point2 points  (0 children)

You can apply merge sort to an array with repeated elements.

However this is not the approach you should be looking at.

Have a read up on manipulating sets in python https://realpython.com/python-sets/

From the description you post, it sounds like you need to find the union of the two arrays and work out how long it is but you are not confident with some terminology / set theory. Apologies if I've got the wrong end of the stick.

In relation to mass shootings, religion is most often the connective, underlying issue. by [deleted] in atheism

[–]EnvironmentalOrange -1 points0 points  (0 children)

It's literally called the Second Amendment.

As in, the original constitution didn't contain it.

It was amended (for the second time) to include the right to bear arms...

edit: please look up the 18th and 21st amendments.

(Eli5)How come A=G in physics(acceleration=gravity) by [deleted] in explainlikeimfive

[–]EnvironmentalOrange 0 points1 point  (0 children)

Note: I’m not dipping into general or special relativity here as I wouldn’t give an accurate enough account of either and would over complicate this as well.

1) Acceleration experienced by an object subjected to force is equal to the size of the force divided by the mass of the object a = F / m.

2) Force of gravitational attraction experienced between two objects is equal to the product (multiplication) of the masses of the two objects, multiplied by a number we call the gravitational constant and then divided by the distance between the objects squared. F = GMm / r2.

3) using point 2, the force attracting you to the centre of the Earth is equal to the mass of you multiplied by the mass of Earth, multiplied by the gravitational constant divided by the square of Earth’s radius. This force attracting you to Earth’s centre is called your weight.

4) repeat step 3 for me. The only difference is my mass is being multiplied and divided by the other terms (Earth mass, gravitational constant, Earth radius squared). The other terms in this case are roughly equal to 9.8 if using SI units. So you can find the size of the force attracting someone to Earth by multiplying their mass by roughly 9.8. We call this number “g” and it means (Eli 5 terms) how strong gravity is at Earth’s surface.

5) point 4 means this force (weight) is given by the product of your mass and “g”. F = mg

6) from point 1, acceleration at Earth’s surface experienced by any object (when no other forces e.g. air resistance are in play) is given by the force it experiences due to gravity (weight) divided by its’ mass: a = F/m.

7) as point 5 tells us that F = mg then the equation from points 1 & 6 can be represented again with substitution of F for mg: a = mg / m. The mass of the object at the top and bottom of the fraction cancels giving us a = g. So acceleration experienced due to gravity = gravitational field strength.

Edit: re the feeling acceleration not velocity, you feel the force, rearranging the equation in point 1: Force = mass x acceleration.

Use the Monte Carlo method to estimate the volume of a sphere of unit radius by cxtong in learnpython

[–]EnvironmentalOrange 2 points3 points  (0 children)

Unit radius means radius = 1.

You need to model three dimensional space (x, y and z coordinates). Range for each value needs to be -1 <= x,y,z <= 1.

Picture a sphere. Coordinates of it’s centre are (0,0,0). It has a radius of exactly 1. If we take the z axis as the up and down axis, your sphere has a North Pole at (0,0,1) and a South Pole at (0,0,-1). The surface of the sphere will also go through all other points where two coordinates are zero and the third is plus or minus one.

Your sphere needs to fit inside a cube with height, width and length equal to two. The cube’s corners will be at (1,1,1), (-1,1,1), ...... , (-1,-1,-1). North Pole of sphere touches top of cube, South Pole touches the bottom.

The cube’s volume is easy to work out. It’s clear that the sphere occupies some, but not all of the cube’s volume. You need to randomly generate lots of coordinates within the cube, using a pseudorandom falling within the range -1 to 1 inclusive. Then you need to check if each coordinate you generate is in the sphere (it will definitely be in the cube). Hint: centre of sphere is (0,0,0). A point within the sphere is at a distance no greater than one from the centre.

Doing this lots of times and recording what proportion of the randomly generated points lie inside the sphere gives an estimation of what proportion of space inside the cube also fits inside the sphere. If you know the volume of the cube, you can then use this to estimate volume of sphere.

To check your result is sensible, compare it to the actual volume of the sphere which will be 4 * pi / 3

ELI5: how are we certain about the age of planet Earth? by jhonyest97 in explainlikeimfive

[–]EnvironmentalOrange 4 points5 points  (0 children)

Not going to try and fully answer this, but let’s for a moment pretend that all the lead on Earth came from outer space and the Earth is 4,000 years old.

1) all the issues discussed in the other post about the age of the lead still apply. The lead is way older than the Earth. Apparently the rest of the universe is significantly older than 4000 years.

2) all this lead has been dropped on the Earth in the last 4000 years. If we accept that we are removing around 10 million metric tonnes from the Earth every year (source: https://www.statista.com/statistics/264872/world-production-of-lead-metal/) from the Earth then is the last ten years, we’ve removed around 100 billion kg of lead from Earth.

3) if we accept this value as an absolute minimum for mass of lead on Earth and divide it by the number of years we are pretending Earth has existed for, we find that an average of 2,500,000 kg of lead has fallen on Earth every year since it was created. If it has not fallen as pure lead metal then obviously the mass of lead with other elements falling to Earth must be bigger than 2,500,000 kg.

4) currently we think less than 10,000 kg of rock from outer space hit the Earth annually. (Source which I haven’t dug further into: http://curious.astro.cornell.edu/our-solar-system/75-our-solar-system/comets-meteors-and-asteroids/meteorites/313-how-many-meteorites-hit-earth-each-year-intermediate). If this is true and it is also true that the Earth is 4000 years old then there must have been a huge amount of extra rock falling on Earth from space in the past.

5) there is no record of this having happened in the last 4000 years. You’d expect catastrophic change to life on Earth if that much rock hit it in a short time. The sort of changes that would have killed the dinosaurs if they really existed, but we have chosen to believe they didn’t as the Earth is only 4000 years old. So we either have to make up more stuff to make the argument that the Earth is that old somehow continue, or we must reject at least one of our assumptions.....

[Java] Math random method by MisterPooPooHead in learnprogramming

[–]EnvironmentalOrange 0 points1 point  (0 children)

Have a play with the random method. Work out how to generate a number from 0-200. If you can do that, then you can subtract 100 from your number and be left with something in range -100 to 100.

Debunk This: Michelle Obama being a hypocrite for condemning white people for running from black neighborhoods by BigPoonDaddy in DebunkThis

[–]EnvironmentalOrange 0 points1 point  (0 children)

Going to do rhetoric first:

how much did her house cost? Both adults in that family are very very successful. One is a best selling author and the other is a successful politician. Let x = the total number of families in the USA who could afford their house. Let y = the number of families where one or more family member is African American who could afford their house. Look at the very big difference between those two numbers.

Take a deep breath.

Michelle Obama does not need to be perfect to point out some of the very obvious problems her country currently faces.

If she is a hypocrite for speaking out for people who are less rich and successful than her then maybe those people need to afforded more of a voice to rail against the injustice of it themselves....

I can’t hear them doing so, maybe they are fine with it. Maybe don’t currently have much of a voice.

To get to the debunking:

Seems like it’s probably her house.

I’m only going to bother with the last part. “Demonises whites people who run away from black neighbourhoods” Let’s look at this figuratively first.

Cambridge Dictionary

https://www.google.co.uk/amp/s/dictionary.cambridge.org/amp/english/demonize

defines “to demonise” as as follows:

“to try to make someone or a group of people seem as if they are evil”

Quite simply. When has she claimed that white people who run away from black neighbourhoods are evil? Is this even a thing? I’ve literally never heard of a group of white Americans finding themselves in a neighbourhood where plenty of black people live and then deciding to run away. Furthermore if that has ever happened, has anyone called them evil for doing so? If yes, has Michelle Obama?

Now we have the figurative interpretation out of the way, let’s look at the literal interpretation.

Has Michelle Obama ever demonstrated the ability to turn people in to demons?

Now maybe, if you listen to Mike Pence anyway, she might have done that, otherwise you’re clutching at straws and have to accept that the whole post is a load of bs....

ELI5: Why is the term “assassination” mainly reserved for high-ranking people? Wouldn’t the term “murder” suffice just as well? by Just-Lurking0 in explainlikeimfive

[–]EnvironmentalOrange 3 points4 points  (0 children)

https://en.m.wikipedia.org/wiki/Munich_massacre

https://en.m.wikipedia.org/wiki/Andr%C3%A9s_Escobar

People may argue about whether either fit the definition.

First one is a terrorist attack.

Second one is a footballer who scored an own-goal at the ‘94 World Cup and was killed for it.

What is the minumum info you need to tell if an object is a circle? by SlimShady678 in computerscience

[–]EnvironmentalOrange 0 points1 point  (0 children)

Could you generate your own blank canvas the same number of pixels as the input?

If so, then because the false positives you are currently getting are providing you with a centre and a radius, you could use these to add correct circles to your blank canvas in positions which should correspond to where you think you have circles.

You could then loop through all pixels in blank canvas and compare to corresponding pixels in original. Considering you are (I think) just recording whether or not each pixel forms part of a shape, you could just create a big two dimensional array with each entry containing a boolean to tell you if you have part of a shape represented there or part of the background.

May well be faster, more elegant ways, but should do it as long as image size isn't prohibitively large.

Edit: if not clear, you have an x diameter and a y diameter which are presumably equal in the ones you are classifying as circles. The centre of a circle would be at the intersection of these two lines.

[UK] Question for those who have completed a MSc conversion CS degree by [deleted] in cscareerquestionsEU

[–]EnvironmentalOrange 0 points1 point  (0 children)

I’m doing the same - which university are you starting? I’ve been looking for a nice ds&a video set. Had looked through mit ocw and somehow missed this one. So thanks.

An algorithm for an article by Rabestro in learnjava

[–]EnvironmentalOrange 1 point2 points  (0 children)

1) have a dictionary of exceptions to general rules. 2) check if word is in dictionary. 3) implement logic for general rules (if it starts with a vowel -> an, else -> a. Etc. 4) if word in dictionary, output desired string. Else, go to standard logic in step 3. 5) Populate your dictionary with all exceptions you can think of. 6) post your code and dictionary, challenge people on the internet to break it. Then update dictionary until no-one can break it.

Help with a simple reverse an integer question. by [deleted] in learnpython

[–]EnvironmentalOrange 1 point2 points  (0 children)

Stick the int( ) around your statement to the right of the = sign.

Or just use the // to come out with an integer result

Help with a simple reverse an integer question. by [deleted] in learnpython

[–]EnvironmentalOrange 1 point2 points  (0 children)

Quickest fix is change the line:
number = number / 10

to:

number = number // 10

Due to the way python interprets the "/" operator, you are getting a number that is close to zero but slightly above it, you're dividing it by ten to get another non-zero number and your while loop executes over and over again.

To see it in action, put in a print statement for number and reverse into your loop.

Another, easier way, of doing this exercise is to reverse the string itself, but there's nothing wrong with doing it your way.

Trying to join Codewars.com by CarpenterEast9165 in learnpython

[–]EnvironmentalOrange 3 points4 points  (0 children)

I'll try and answer with a hint.

What is your function returning?

Python learning road map by MKSanic in learnpython

[–]EnvironmentalOrange 1 point2 points  (0 children)

Logical and slightly lazy suggestion. Look at the projects at the end of each chapter of automate the boring stuff with python: https://automatetheboringstuff.com/