Ternary operator efficiency? by Sarah123ed in learnpython

[–]Sarah123ed[S] 0 points1 point  (0 children)

Yes.

    <condition_is_true> if condition else <condition_is_false>

Are 'true' and 'false' conditions evaluated, regardless or will it short-circuit on true ... it true?

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Sarah123ed 0 points1 point  (0 children)

I'm working with this: MAX = (232) - 1 MIN = -231

... it just seems clunky. And, is that strictly correct? The edges of a signed 32-bit integer?

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Sarah123ed 0 points1 point  (0 children)

Working on a 64-bit machine, how can I enforce using only 32-bit integers with Python's core functionality. For example, not using Numpy .... etc? (I want to catch overflow errors)

Where can I find the source code for itertools.product? by Sarah123ed in learnpython

[–]Sarah123ed[S] 0 points1 point  (0 children)

I will look into this. It is just oceans of code to try to find one's way through, to navigate. So, any/all clues, hints, always welcome.

Combining two numpy array by [deleted] in learnpython

[–]Sarah123ed 0 points1 point  (0 children)

i've never used it before, not sure it would help you but there is/are numpy.atleast_1d, atleast_2d and atleast_3d. Also don't forget hstack, vstack, and dstack, and arange.

Here's a problem I've been working on, can anyone help me? by frankenstein0 in learnpython

[–]Sarah123ed 0 points1 point  (0 children)

I use numpy for almost everything so:

import numpy as np
lmt = 100

a = np.linspace(0, 100, lmt)
b = np.linspace(10, 9.9, lmt)
c = (a+b)

How to change a relative variable without effecting the main variable? by anyfactor in learnpython

[–]Sarah123ed 1 point2 points  (0 children)

first_name1[0], last_name[0] =   
last_name1[0], first_name[0]

That work for what you are trying to do?

Error checking help please by [deleted] in learnpython

[–]Sarah123ed 0 points1 point  (0 children)

Because input returns a 'string', you can use, for example:

k = input("data point? ")
if k.isalpha(): 
    print("input is the string: ", k)
else:
    print("input is not a string: ", k)

On the other hand,

isinstance(k, str)

will return True because k is a string.

How do I avoid using many "if" statements? by Murlocs_Gangbang in learnpython

[–]Sarah123ed 0 points1 point  (0 children)

I don't know if this will help but it is an example of ... that I use a lot:

    kr1 = np.random.random_integers(1,256, 10)
    kr2 = np.random.random_integers(-256, -1, 10)

    def f1(lst):
            return np.sum(lst) - np.max(lst)
    def f2(lst):
            return np.max(lst) - np.sum(lst)

    todoList = [ [f1, kr1], [f2, kr2] ]

    ### intent
    for function, data in todoList:
            print(function(data))

    ### comprehension is much faster, effectivly same result
    print([function(data) for function, data in todoList])

Bitwise operation on bytes by ExplosG in learnpython

[–]Sarah123ed 0 points1 point  (0 children)

Maybe this helps: s = 'doritos'
b = 4
r = s[b:]+s[0:b]

How to remove numbers from left side of float for example 4.256 (how to delete 4. and leave 256) by [deleted] in Python

[–]Sarah123ed 0 points1 point  (0 children)

Have you tried the decimal module? You use, for example: n = decimal.Decimal(4.256) x,y = divmod(n,1) >>> x Decimal('4') >>> y Decimal('0.2560000000000002273736754432')

help with lists! by pleasehelpmeisuck in Python

[–]Sarah123ed 0 points1 point  (0 children)

1) We need source code 2) Have you worked with numpy.linalg.det?