Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
code:
while searchLength > 0:
	if cleanString[searchLength] == cleanString[-searchLength]:
		searchLength -= 1
	else:
		return False
	return True
is equivalent to
code:
while searchLength > 0:
	if cleanString[searchLength] == cleanString[-searchLength]:
		searchLength -= 1
		return True
	else:
		return False
is equivalent (given that searchLength is local) to
code:
while searchLength > 0:
	if cleanString[searchLength] == cleanString[-searchLength]:
		return True
	else:
		return False
is equivalent to
code:
while searchLength > 0:
	return cleanString[searchLength] == cleanString[-searchLength]

Adbot
ADBOT LOVES YOU

Xeno54
Apr 25, 2004
bread

Popular Thug Drink posted:

i'm trying to make a palindrome tester, what am i doing wrong here?

code:
def palindromeCheck(rawString):
	#convert input to lowercase
	lowerString = rawString.lower()
	#clean out any punctuation
	cleanString = lowerString.translate(None, '! .,')
	#find half the length of the result
	searchLength = len(cleanString) / 2
	#compare char to char, starting from the middle and working outwards, ignoring the middle char of odd numbered strings
	while searchLength > 0:
		if cleanString[searchLength] == cleanString[-searchLength]:
			searchLength -= 1
		else:
			return False
		return True	
rawString = raw_input("Give me a Palindrome: ")
isPalindrome = palindromeCheck(rawString)
if isPalindrome == True:
	print "This is a Palindrome!"
else:
	print "Sorry, this is not a Palindrome."
the problem is i can't get it to iterate through the if, i had assumed "while searchLength is still greater than 0 keep doing the if"

The "return True" is over indented and inside the while loop, so your code will either return True or False on the first iteration (see Hammerite's analysis). You should be good if you remove an indent and have "return True" at the same level as the while loop.

Xeno54 fucked around with this message at 14:25 on Oct 13, 2015

boner confessor
Apr 25, 2013

by R. Guyovich

Xeno54 posted:

The "return True" is over indented and inside the while loop, so your code will either return True or False on the first iteration (see Hammerite's analysis). You should be good if you remove an indent and have "return True" at the same level as the while loop.

i thought i tried that, huh. so if i do that, then 'while the counter is whatever if comparison is still valid deincrement searchLength and try again' is the expected behavior?

e: haha, that was the correct placement of the return in my previous test, but i forgot to test for str[index] == str[index-1]], and one of my test words was 'banana', which is a valid offset palindrome under that logic...

boner confessor fucked around with this message at 15:57 on Oct 13, 2015

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Perhaps you want some more practice with loops, but, reminder: a palindrome is a word that is the same forwards and backwards.

lord of the files
Sep 4, 2012

SurgicalOntologist posted:

This my first foray into scraping Javascript pages, and I'm trying to use dryscrape which is based on QT webkit. If everything is working correctly I should be triggering a "download file" popup. How do I catch the file the site is trying to send me, ideally into a string but I would be happy reading it again off the local file system.

is your download being triggered by redirecting you to another page? if it is, you can extract the url from the previous page with dryscape and parse the download link out of that, then use python's HTTP library to load the binary data into a string, such as this:
code:
my_silly_file = urllib2.urlopen(extracted_dryscape_url).read()
dryscape is a web parser and does not have any functions to handle downloading of files, so you will have to use something external to it to download your data.

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

Popular Thug Drink posted:

i'm trying to make a palindrome tester, what am i doing wrong here?

Here is what I would consider a more Pythonic palindrome tester (not vigorously tested but seems to work); that is, it uses a comprehension (use comprehensions everywhere). This is Python 3 code, but will work in Python 2 if you remove the annotations from the method signature and use def is_palindrome(palindrome): instead:
Python code:
def is_palindrome(palindrome: str) -> bool:
    return all(palindrome[i] == palindrome[-i-1] for i in range(len(palindrome)) if i < len(palindrome)//2)
This function doesn't strip punctuation, but it expresses the concept of scanning a string to compare characters from both ends in a very concise fashion. This isn't really a Python-specific thing, it's just thinking algorithmically and figuring out what parts of the algorithm are actually important.

The way this works is as follows:
  • all() is a function that will return True if every element of the iterator within is true (e.g., all([True, True, True]) will return True, but all([True, False]) will return False)
  • palindrome[i] == palindrome[-i-1] compares the character at i with the character mirroring i at the other end of the string (you can write it more lengthily as len(palindrome)-1-i; the extra -1 is to avoid an IndexError when comparing the first character
  • for i in range(len(palindrome)) generates an iterator that emits the length of the string one step at a time (0, 1, 2, 3, etc.)
  • if i < len(palindrome)//2 is a Python 3-ism that forces integer division; this will return things like 9/2==4, but with a palindrome you don't actually need to care about the center character if there are an odd number of characters in the string

It is surprisingly common to be able to distill logic into a comprehension in Python, and it's a really valuable pattern to use; smart use of comprehensions is one of the best things you can do for keeping things concise in Python, since the rest of the language can require some extra verbosity that other languages don't. Importantly, it also forces your logic into a single line that reads pretty naturally with a little experience: you can read the comprehension as "this will return a list of boolean values that say whether the character at positions i and the mirror of i were the same while comparing characters in the string through the first half of the string".

SurgicalOntologist
Jun 17, 2004

I can't resist, even though Suspicious Dish already hinted at it in a much more pedagogical manner. But here's my solution:
Python code:
def is_palindrome(x):
    return ''.join(reversed(x)) == x

Nitrocat posted:

is your download being triggered by redirecting you to another page? if it is, you can extract the url from the previous page with dryscape and parse the download link out of that, then use python's HTTP library to load the binary data into a string, such as this:
code:
my_silly_file = urllib2.urlopen(extracted_dryscape_url).read()
dryscape is a web parser and does not have any functions to handle downloading of files, so you will have to use something external to it to download your data.

I used Chrome dev tools to find the POST that generates the data, but it includes a whole lot of json. I tried copy-pasting it from Chrome and keep getting JavaScript errors. I still need to try copy-pasting the headers as well. But I'm wondering if it would be possible to use dryscrape or a similar tool to get the POST payload that gets sent when I click the "download" button. Then I send that payload through requests.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

SurgicalOntologist posted:

I can't resist, even though Suspicious Dish already hinted at it in a much more pedagogical manner. But here's my solution:
Python code:
def is_palindrome(x):
    return ''.join(reversed(x)) == x

Python code:
def is_palindrome(x):
    return x == x[::-1]
Is what I usually see for idiomatic Python.

KICK BAMA KICK
Mar 2, 2009

Suspicious Dish posted:

Python code:
def is_palindrome(x):
    return x == x[::-1]
Is what I usually see for idiomatic Python.
Yeah, that (with any sanitization you want like .lower()) is what I'd call the most idiomatic.

Cingulate
Oct 23, 2012

by Fluffdaddy
In matplotlib, I want to create axes at arbitrary positions who share size and yaxis/xaxis with some other axis.
That is, I have created an axis, and now I want to create another axis at another position with the same extent, but different origin.

I do not see an elegant way of doing this. Any tips?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



SurgicalOntologist posted:

I used Chrome dev tools to find the POST that generates the data, but it includes a whole lot of json. I tried copy-pasting it from Chrome and keep getting JavaScript errors. I still need to try copy-pasting the headers as well. But I'm wondering if it would be possible to use dryscrape or a similar tool to get the POST payload that gets sent when I click the "download" button. Then I send that payload through requests.

In the Netowrk tab of the Chrome dev tools, you can copy the request as a cURL command which will include the headers. You can also just copy the headers to see what's being sent and incorporate that into a urllib request.

BannedNewbie
Apr 22, 2003

HOW ARE YOU? -> YOSHI?
FINE, THANK YOU. -> YOSHI.

Cingulate posted:

In matplotlib, I want to create axes at arbitrary positions who share size and yaxis/xaxis with some other axis.
That is, I have created an axis, and now I want to create another axis at another position with the same extent, but different origin.

I do not see an elegant way of doing this. Any tips?

Do you have an example of the kind of figure you are trying to create?
My guess of the way to approach this is to create another subplot with the same axis size, and the use subplot2grid() to move it where you want.

Tacos Al Pastor
Jun 20, 2003

Im not sure I get virtualenv. I tried to install Flask on my Mac per the instructions, but the default is to run 2.7.10 whereas I'm using 3.2. Anyone know how to fix this?

Cingulate
Oct 23, 2012

by Fluffdaddy

BannedNewbie posted:

Do you have an example of the kind of figure you are trying to create?
My guess of the way to approach this is to create another subplot with the same axis size, and the use subplot2grid() to move it where you want.
The problem is mainly, how do I know the first axes' size?

OnceIWasAnOstrich
Jul 22, 2006

spiralbrain posted:

Im not sure I get virtualenv. I tried to install Flask on my Mac per the instructions, but the default is to run 2.7.10 whereas I'm using 3.2. Anyone know how to fix this?

You will have installed virtualenv as a package of some Python. If you then use virtualenv to create a virtual environment, by default it will create a venv for the Python that it is installed to. Python 2.7.10 is the system Python for new versions of OSX, so I am guessing you installed virtualenv to that Python instead of your 3.2 (simply installing 3.2 will not overwrite the system Python and the system Python remains the default unless you specifically change your PATH variable). You can still use this virtualenv with Python 3.3 by specifying which interpreter you want when you create the venv, something like virtualenv -p /usr/local/bin/python3 mypy32env.

BannedNewbie
Apr 22, 2003

HOW ARE YOU? -> YOSHI?
FINE, THANK YOU. -> YOSHI.

Cingulate posted:

The problem is mainly, how do I know the first axes' size?

Again, it would be easier to help you out if I had a clear understanding of what you're trying to do, but something like this might work:

code:
# first set of axes
ax = plt.subplot2grid((2,2),(0, 0))
plt.plot(stuff)
# grab the dimensions of your first plot
x_dimensions = plt.xlim()
y_dimensions = plt.ylim()

# second set of axes
ax = plt.subplot2grid((2,2),(0,1))
plt.plot(more_stuff)
plt.xlim(x_dimensions)
plt.ylim(y_dimensions)

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

Suspicious Dish posted:

Python code:
def is_palindrome(x):
    return x == x[::-1]
Is what I usually see for idiomatic Python.

the magnificent burn of being ultra code golfed

Gangsta Lean
Dec 3, 2001

Calm, relaxed...what could be more fulfilling?
That isn't code golf at all. That is indeed the most straightforward way to test a palindrome in any language.
1. Create a reversed copy of the original string.
2. Compare the copy to the original, testing for equality.

It just so happens that the idiomatic way to reverse a string in Python is short and somewhat cryptic.

Tacos Al Pastor
Jun 20, 2003

OnceIWasAnOstrich posted:

You will have installed virtualenv as a package of some Python. If you then use virtualenv to create a virtual environment, by default it will create a venv for the Python that it is installed to. Python 2.7.10 is the system Python for new versions of OSX, so I am guessing you installed virtualenv to that Python instead of your 3.2 (simply installing 3.2 will not overwrite the system Python and the system Python remains the default unless you specifically change your PATH variable). You can still use this virtualenv with Python 3.3 by specifying which interpreter you want when you create the venv, something like virtualenv -p /usr/local/bin/python3 mypy32env.

This helps. Thank you. I want the virtualenv to be used for Python 3.X (forget which version is loaded on my other laptop) so yeah, currently its not pointed at that and I could see it was giving me a path error for the Flask import when I tried running the basic Flask hello world app so I figured something in the virtualenv wasn't setup correctly. Thanks for that command.

I'm still not exactly sure how the virtual workspace works but it seems as though it makes it easier to switch between 2.7 and 3.x depending on which version you want to work with...also something with dependencies, but thats about all I know. Def need to read up more on this.

Proteus Jones
Feb 28, 2013



spiralbrain posted:

This helps. Thank you. I want the virtualenv to be used for Python 3.X (forget which version is loaded on my other laptop) so yeah, currently its not pointed at that and I could see it was giving me a path error for the Flask import when I tried running the basic Flask hello world app so I figured something in the virtualenv wasn't setup correctly. Thanks for that command.

I'm still not exactly sure how the virtual workspace works but it seems as though it makes it easier to switch between 2.7 and 3.x depending on which version you want to work with...also something with dependencies, but thats about all I know. Def need to read up more on this.

You may want to look into Anaconda Python. I really like conda for creating environments.
code:
conda create -n my_flask
source activate my_flask
conda install flask [additional package] [additional package]
This will create a conda environment with only the packages you need. Conda will figure out all the dependancies flask needs and install those as well. Another nice thing is I can keep the environment using the versions I need for my package dependancies. I'm still playing around with "conda build" so I can bundle up my environments and easily get them set up on the systems I need them.

Another nice thing is I can point PyCharm to the environment directory, and it will take it from there automatically using the conda environment on a project by project basis.

boner confessor
Apr 25, 2013

by R. Guyovich
both of these just flip the string and test that against the input, right? i figured that was more efficient but i wanted to do a step by step comparison

SurgicalOntologist posted:

Python code:
def is_palindrome(x):
    return ''.join(reversed(x)) == x

return is a built in function that produces a bool
'' creates a new empty string?
.join fills in the new string with the reversed input x
== x tests to see if this new string is the same as the input string

Python code:
def is_palindrome(x):
    return x == x[::-1]
and this does the same thing, except using string slicing to start from the end and work backwards at an interval of 1 char per char, effectively reversing the string?

thanks all

QuarkJets
Sep 8, 2008

Popular Thug Drink posted:

both of these just flip the string and test that against the input, right? i figured that was more efficient but i wanted to do a step by step comparison


return is a built in function that produces a bool
'' creates a new empty string?
.join fills in the new string with the reversed input x
== x tests to see if this new string is the same as the input string

return is a keyword that you place inside of a function order to define what that function returns, but return is not a function. In this case the function returns a bool, but a function can return anything. Using == means a comparison is made, and a bool is created from that comparison operation, so returning ''.join(reversed(x)) == x results in a bool getting returned by the function (either True if they are equal, or False if they ar enot)

'' is an empty string

reversed(x) returns a new string. You don't need to use .join with it. You could just call reversed(x) == x. Joining on an empty string is kind of pointless, really, because strings are immutable: in Python you can never put more or less stuff into a string, you can only create a new string. reverse(x) creates a new string that is the reverse of x

.join takes any iterable of strings (say a list of strings, or hey, a string is an iterable of 1-letter strings) and creates a new string out of them, using whatever the string before. join is. In this case, you're using an empty string to join together all of the letters. This is really useful if you want to take a list of strings and separate them with some form of punctuation (commas, or newline characters for instance: printing '\n'.join(['a','test','string'] would result in 3 lines getting printed, one for each word in that list)

== x tests to see if the new string is the same as the input string

quote:

Python code:
def is_palindrome(x):
    return x == x[::-1]
and this does the same thing, except using string slicing to start from the end and work backwards at an interval of 1 char per char, effectively reversing the string?

thanks all

That's right

SurgicalOntologist
Jun 17, 2004

In Python 3 at least you do need to call join, because reversed returns a special iterator object. join with an empty string essentially concatenates any iterator of strings.

Roargasm
Oct 21, 2010

Hate to sound sleazy
But tease me
I don't want it if it's that easy
Recursively you could do:
code:
str = "racecar"
str = str.lower()

def isPal(s):
    if len(s) <= 1:
        return True

    else:
        answer = s[0] == s[-1] and isPal(s[1:-1])
        return answer

print isPal(str)

No Safe Word
Feb 26, 2005

Roargasm posted:

Recursively you could do:
code:
str = "racecar"
str = str.lower()

def isPal(s):
    if len(s) <= 1:
        return True

    else:
        answer = s[0] == s[-1] and isPal(s[1:-1])
        return answer

print isPal(str)

Pro tip: don't name variables str (or list or int, etc.)

vodkat
Jun 30, 2012



cannot legally be sold as vodka
Whats the neatest way to sort a list of integers into other lists? At the moment I've got something and its working fine, but I'm sure its probably a really inefficient way to solve this problem.

code:
for x in pricesort:
    if x >= 50000000:
        fiftymil.append(x)
    if x >=45000000 and x <= 50000000:
        fourtyfivemil.append(x)
and so on all the way down to zero. Obviously this takes up a ridiculous amount of lines for a relatively simply operation so I wondering how else it could be done.

Thots and Prayers
Jul 13, 2006

A is the for the atrocious abominated acts that YOu committed. A is also for ass-i-nine, eight, seven, and six.

B, b, b - b is for your belligerent, bitchy, bottomless state of affairs, but why?

C is for the cantankerous condition of our character, you have no cut-out.
Grimey Drawer

vodkat posted:

Whats the neatest way to sort a list of integers into other lists? At the moment I've got something and its working fine, but I'm sure its probably a really inefficient way to solve this problem.

code:
for x in pricesort:
    if x >= 50000000:
        fiftymil.append(x)
    if x >=45000000 and x <= 50000000:
        fourtyfivemil.append(x)
and so on all the way down to zero. Obviously this takes up a ridiculous amount of lines for a relatively simply operation so I wondering how else it could be done.

Something something integer division. x//5M will equal 9 for 45M-49999999, 8 for 40M-44999999, 7 for 35M-39999999 and etc. If you had a list of lists, you could use the 9,8,7,6 to select the proper list.

No Safe Word
Feb 26, 2005

vodkat posted:

Whats the neatest way to sort a list of integers into other lists? At the moment I've got something and its working fine, but I'm sure its probably a really inefficient way to solve this problem.

code:
for x in pricesort:
    if x >= 50000000:
        fiftymil.append(x)
    if x >=45000000 and x <= 50000000:
        fourtyfivemil.append(x)
and so on all the way down to zero. Obviously this takes up a ridiculous amount of lines for a relatively simply operation so I wondering how else it could be done.

My python is super rusty so this may not be very pythonic or even that efficient but
code:
>>> def segment(nums, segment_size):
...     results = []
...     sorted_nums = sorted(nums)
...     for upper in range(segment_size, max(nums), segment_size):
...             results.append([])
...             x = sorted_nums[0]
...             while x < upper:
...                     results[-1].append(x)
...                     sorted_nums.remove(x)
...                     x = sorted_nums[0]
...     results.append(sorted_nums)
...     return results
>>> nums = [random.randint(0, 1000) for _ in range(100)]
>>> nums
[154, 457, 937, 456, 947, 278, 763, 151, 266, 165, 379, 783, 261, 795, 723, 312, 464, 139, 215, 793, 560, 914, 816, 677, 57,
84, 977, 856, 217, 991, 762, 328, 545, 860, 520, 767, 697, 750, 294, 232, 134, 190, 48, 111, 337, 751, 243, 353, 738, 951, 370,
116, 815, 401, 48, 688, 614, 824, 894, 643, 591, 756, 358, 772, 134, 797, 522, 856, 612, 413, 323, 231, 104, 425, 153, 352,
347, 690, 573, 223, 74, 706, 379, 484, 588, 935, 389, 67, 228, 397, 43, 559, 227, 86, 737, 738, 832, 819, 898, 495]
>>> segment(nums, 10)
[[], [], [], [], [43, 48, 48], [57], [67], [74], [84, 86], [], [104], [111, 116], [], [134, 134, 139], [], [151, 153, 154], [165], [], [], [190], [], [215,
217], [223, 227, 228], [231, 232], [243], [], [261, 266], [278], [], [294], [], [312], [323, 328], [337], [347], [352, 353, 358], [], [370, 379,
379], [389], [397], [401], [413], [425], [], [], [456, 457], [464], [], [484], [495], [], [], [520, 522], [], [545], [559], [560], [573], [588], [591], [],
[612, 614], [], [], [643], [], [], [677], [688], [690, 697], [706], [], [723], [737, 738, 738], [], [750, 751, 756], [762, 763, 767], [772], [783],
[793, 795, 797], [], [815, 816, 819], [824], [832], [], [856, 856], [860], [], [], [894, 898], [], [914], [], [935, 937], [947], [951], [], [977], [], [991]]
>>> segment(nums, 100)
[[43, 48, 48, 57, 67, 74, 84, 86], [104, 111, 116, 134, 134, 139, 151, 153, 154, 165, 190], [215, 217, 223, 227, 228, 231, 232, 243, 261, 266, 278, 294],
[312, 323, 328, 337, 347, 352, 353, 358, 370, 379, 379, 389, 397], [401, 413, 425, 456, 457, 464, 484, 495], [520, 522, 545, 559, 560, 573, 588, 591],
[612, 614, 643, 677, 688, 690, 697], [706, 723, 737, 738, 738, 750, 751, 756, 762, 763, 767, 772, 783, 793, 795, 797], [815, 816, 819, 824, 832, 856, 856,
860, 894, 898], [914, 935, 937, 947, 951, 977, 991]]

This will obviously create a shitload of empty lists if your resultset is sparse, in which case you could cull the empty lists or use a dict if you wanted (would make the -1 go away). Also it doesn't preserve ordering obviously.

e: forgot to append the leftovers, fixed

No Safe Word fucked around with this message at 16:23 on Oct 15, 2015

SurgicalOntologist
Jun 17, 2004

vodkat posted:

Whats the neatest way to sort a list of integers into other lists? At the moment I've got something and its working fine, but I'm sure its probably a really inefficient way to solve this problem.

code:
for x in pricesort:
    if x >= 50000000:
        fiftymil.append(x)
    if x >=45000000 and x <= 50000000:
        fourtyfivemil.append(x)
and so on all the way down to zero. Obviously this takes up a ridiculous amount of lines for a relatively simply operation so I wondering how else it could be done.

You should be using numpy.

Python code:
pricesort = np.asarray(pricesort)
fiftymil = pricesort[pricesort >= 50000000]
fourtyfivemil = pricesort[(pricesort >= 45000000) & (pricesort < 50000000)]

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

SurgicalOntologist posted:

You should be using numpy.

Overkill for something so basic that can easily be done just using Python.

Python code:
def sort_into_bins (iterable, bin_interval_size):
    from collections import defaultdict
    lists = defaultdict(lambda: [])
    for item in iterable:
        lists[bin_interval_size * (item // bin_interval_size)].append(item)
    return lists

sorted_items = sort_into_bins(pricesort, 5000000)

SurgicalOntologist
Jun 17, 2004

Hammerite posted:

Overkill for something so basic that can easily be done just using Python.

That's fair, if it's really just this one thing. But someone who can benefit from array indexing once is likely to benefit from it in other places as well.

QuarkJets
Sep 8, 2008

SurgicalOntologist posted:

In Python 3 at least you do need to call join, because reversed returns a special iterator object. join with an empty string essentially concatenates any iterator of strings.

:downs:

QuarkJets
Sep 8, 2008

Hammerite posted:

Overkill for something so basic that can easily be done just using Python.

Python code:
def sort_into_bins (iterable, bin_interval_size):
    from collections import defaultdict
    lists = defaultdict(lambda: [])
    for item in iterable:
        lists[bin_interval_size * (item // bin_interval_size)].append(item)
    return lists

sorted_items = sort_into_bins(pricesort, 5000000)

Numpy is Python

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

QuarkJets posted:

Numpy is Python

Probably what he means is "can be done with the Python standard library without needing to install anything".

Nippashish
Nov 2, 2005

Let me see you dance!

chutwig posted:

Probably what he means is "can be done with the Python standard library without needing to install anything".

I don't understand, why would you install python without installing numpy?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Nippashish posted:

I don't understand, why would you install python without installing numpy?

Because it's the path of least resistance to just install standard Python, and you don't need to do things that numpy is designed to do (i.e. intensive number-crunching)?

I had just python installed on my machines for ages. Recently I installed another Python distribution that has numpy included because I wanted to play around with a neural network library, and I concluded from reading about the amount of matrix maths involved that it would be needed (and besides the library I wanted to use had it as a dependency). If I hadn't been looking at that then I still wouldn't have it installed because day-to-day I don't really use Python to do number-crunching, just to script stuff, and it's fast enough for that purpose.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Nippashish posted:

I don't understand, why would you install python without installing numpy?

Because the vast majority of things people do with Python get no particular benefit out of numpy?

vikingstrike
Sep 23, 2007

whats happening, captain

Thermopyle posted:

Because the vast majority of things people do with Python get no particular benefit out of numpy?

This. When I first started using python I had no needs outside of the standard library, but once I started doing my data analysis/cleaning/plotting in python I moved over to the Anaconda distribution since pandas, numpy, and MPL are daily drivers for me now. Once of the things I loved as a beginner to the language was how robust (at least to me) the standard library was in helping me do what I needed.

lord of the files
Sep 4, 2012

Thermopyle posted:

Because the vast majority of things people do with Python get no particular benefit out of numpy?

correct. the majority of python users don’t have much of a user for libraries like numpy, matplotlip, panda’s, etc. the standard library is robust enough for what most developers need. i use those libs for data plotting and statistical analysis but for operations that can easily be done in the standard library with a couple lines of code extra, numpy is not needed. why implement a third party lib unnecessarily?

Adbot
ADBOT LOVES YOU

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
I usually agree that numpy is overkill for most general stuff... But man, for this particular case array indexing fits like a glove as SurgicalOntologist showed.

So I would've posted this instead:

SurgicalOntologist posted:

You should be lusting for numpy.

  • Locked thread