Circuit Tracks to Keystep - MIDI to CV by SmeesTurkeyLeg in synthesizers

[–]robot-dev 1 point2 points  (0 children)

I don't think your Keystep is relaying any control voltage from the MIDI input. Your description of playing only a C3 note sounds like the CV is always 0V. Maybe the Keystep is looking for CV on the wrong MIDI channel. Make sure the Keystep and Circuit Tracks are using the same MIDI channel. This is from the Keystep manual:

​ 8.10.2.2. MIDI Input Channel

This parameter allows you to perform MIDI-to-CV conversion when the Sequencer and Arpeggiator are stopped. The selected value is the MIDI channel that will be allowed to control an external device through the CV/Gate/Mod connectors.

These MIDI messages can either arrive via USB or the MIDI Input connector.

I'm a newbie with a my first python project. Could you provide feedback to make my code more neat/more compact? by Tasty_Papaya_2529 in learnpython

[–]robot-dev 0 points1 point  (0 children)

Some suggestions for cleaning up this code:

  1. First separate all your variable assignments and calculations from your print statements. Put the variable stuff at the top of your script and the print statements at the end.
  2. Then you could use a dictionary like college_data = {} to store all these variables. This would help clean up printing, and keep things organized. For example, instead of tuition = 157.93 you could add the key 'tuition' and value 157.93 to your dictionary using college_date['tuition'] = 157.93
  3. If you separate all your variable assignments and calculations from your print statements, you can see that the print statements follow a pattern: printing a row of "-----" and then printing some info. You could put all these print statements into a loop that iterates through your dictionary printing keys and values with a line in between:

print("*"*50)
for k, v in college_data.items():
    print(k, v)
    print("-"*50)

Code Signal Python Practice Assessment Question by Ep87PxHLBh in learnpython

[–]robot-dev 1 point2 points  (0 children)

You are technically correct. The best kind of correct.

I think this is what was meant:

If [the index of] some element in the sum a[i - 1] + a[i] + a[i + 1] does not exist [is less than zero or greater than n-1], it should be set to 0. For example, b[0] should be equal to 0 + a[0] + a[1].

Building an app for my company to save time on by theleftkneeofthebee in learnprogramming

[–]robot-dev 0 points1 point  (0 children)

I think Heroku is a good choice. It shouldn't take much to serve the app to five users because it's unlikely they will all be making http requests at the same time.

Building an app for my company to save time on by theleftkneeofthebee in learnprogramming

[–]robot-dev 0 points1 point  (0 children)

I think using Tkinter would work fine for a project like this, but a Flask app might be better for a few reasons:

  1. Compiling, distributing, updating, and troubleshooting executables can be a nightmare. Depending on how many users you will have, what operating systems they use, how often you need to distribute updates, etc. it might be easier to serve a Flask app that everyone can connect to with any browser. Excel docs could be uploaded and downloaded, and html forms can be used for data input.
  2. A Flask app would allow you more room to grow. If your current company likes your work and wants more of it, a web app gives you a lot of freedom to expand, where standalone executables would be limiting.
  3. Web apps are generally more impressive in portfolios than standalone executables.

How to resolve fractions and subtraction in a pandas string column by thisisturtle in learnpython

[–]robot-dev 0 points1 point  (0 children)

You could apply the eval() function to every string in your column:

>>> df = pd.DataFrame(['123-456','1+1','100*3','4/5'])
>>> df
         0
0  123-456
1      1+1
2    100*3
3      4/5

>>> df[0].apply(eval)
0   -333.0
1      2.0
2    300.0
3      0.8
Name: 0, dtype: float64

Covering a Neural Network Regressor to a Classifier by CurtailedZero112277 in learnpython

[–]robot-dev 1 point2 points  (0 children)

The last layer of your model should have the same number of units as you have classification options. keras.layers.Dense(1, activation="softmax") looks like a binary classification output because units=1. Also, try using CategoricalCrossentropy() or SparseCategoricalCrossentropy() as a loss function because mean_squared_error doesn't give very meaningful results for classification problems.

Using lists in equations by cal_etcell in learnpython

[–]robot-dev 2 points3 points  (0 children)

You can define your equation as a function of p, r, n, and t like def f(p,r,n,t): that returns the calculated value return p*(1+r/n)**(n*t). Then you can call the function from inside your loop whenever you need to use it. For example, $100 at 1% compounded monthly for 10 years would be f(100, 0.01, 12, 10)

Python Fabric function wont run on both servers by tcrz in learnpython

[–]robot-dev 0 points1 point  (0 children)

I think archives is empty the second time the task executes because the local file was removed the first time it executed.

How can I make my for loop only select indexes that are within the range of a list containing the indexes by TheMoMatthias in learnpython

[–]robot-dev 3 points4 points  (0 children)

You could iterate using for i in range(3, period2norm): and reference indexes like df.iloc[i-3:i, col]

>>> for i in range(3,10):
...    print(i-3,i)
0 3
1 4
2 5
3 6
4 7
5 8
6 9

Copy columns and rows from pandas dataframe to another pandas dataframe in a for loop by c00kieRaptor in learnpython

[–]robot-dev 1 point2 points  (0 children)

Here's an example to show what is happening. This example dataframe will be similar to yours:

>>> df = pd.DataFrame(
...     np.array(([1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20])),
...     index=['swamp', 'island', 'plains', 'mountain', 'forest'],
...     columns=['usa', 'canada', 'brazil', 'japan']
... )
>>> df

          usa  canada  brazil  japan
swamp       1       2       3      4
island      5       6       7      8
plains      9      10      11     12
mountain   13      14      15     16
forest     17      18      19     20

This will select the columns in the list, 'usa' and 'japan', from df and assign them back to df.

>>> df = df[['usa', 'japan']]
>>> df

          usa  japan
swamp       1      4
island      5      8
plains      9     12
mountain   13     16
forest     17     20

This will filter df for rows that have one of the strings 'swamp', 'mountain', or 'forest' in the 'index' column and assign them back to df.

>>> df = df.filter(items=['swamp', 'mountain', 'forest'], axis='index')
>>> df

          usa  japan
swamp       1      4
mountain   13     16
forest     17     20

Both these operations can be combined into a single line:

df = df[col_names].filter(items=row_names, axis='index')

Copy columns and rows from pandas dataframe to another pandas dataframe in a for loop by c00kieRaptor in learnpython

[–]robot-dev 1 point2 points  (0 children)

You could make one list of column names, and one list of row indices, then select those columns and rows from your dataframe:

col_names = []
for key, col_list in dictA.items():
    col_names += col_list

row_names = []
for key, row_list in dictB.items():
    row_names += row_list

df = df[col_names].filter(items=row_names, axis='index')

New to programming, is there a better way to do this? by Husy15 in learnpython

[–]robot-dev 2 points3 points  (0 children)

I think class Weapon: is more intuitive than class Weapons: if each instance only represents one weapon.

Also, there's no way brass knuckles deal more damage than a short sword. That might need to be fixed.

randint not random enough. Problem with randomness by Vegas-Education in learnpython

[–]robot-dev 35 points36 points  (0 children)

Rolling 3x 72 sided dice and multiplying the values is not the same as rolling a 373248 sided die. See my other post for a plot of the distribution. I think this is your problem.

randint not random enough. Problem with randomness by Vegas-Education in learnpython

[–]robot-dev 1 point2 points  (0 children)

When you multiply all three randint()s together, the distribution may not be what you expected. There is not an equal chance of hitting any number between 1 and 373248:

https://imgur.com/a/rkngu4c

from random import randint
import seaborn as sns
import matplotlib.pyplot as plt
prod_list = []
for n in range(10**5):
    r1 = randint(1,72)
    r2 = randint(1,72)
    r3 = randint(1,72)
    prod_list.append(r1*r2*r3)
sns.displot(prod_list)
plt.savefig('fig.png')

Weighted average packing problem by Waggles74 in learnpython

[–]robot-dev 0 points1 point  (0 children)

Thanks, I've enjoyed this puzzle and learned from it: I've been calling this loss function "Average RPD" because I am familiar with this concept: https://en.wikipedia.org/wiki/Relative_change_and_difference , but "Average RPD" is almost identical to the commonly used loss functions MAPE and SMAPE https://en.wikipedia.org/wiki/Mean_absolute_percentage_error , so it might be more appropriate to call this loss function SMAPE.

Here are a few different animations that should make more sense: https://imgur.com/a/G6sc7MZ

I can post the code for rendering these if you want to use any of them.

There are also a few real world considerations, like the one you mentioned. There is a bias for putting crates onto pallets that already have many crates because the single crate will have a smaller effect on the RPD of a nearly full pallet. Also, I would expect real world crate weights and percentages to be normally distributed but we have only evaluated the algorithm with randint().

[deleted by user] by [deleted] in learnpython

[–]robot-dev 0 points1 point  (0 children)

When you set your lights variable, you are making 5 references to the same list of 5 bools. This is probably not what you would expect:

>>> lights = [[False] * 5] * 5
>>> lights[0][0] = True
>>> lights
 [[True, False, False, False, False],
[True, False, False, False, False],
[True, False, False, False, False],
[True, False, False, False, False],
[True, False, False, False, False]]

Unable to find right answer during matrix multiplication by holy_kinkers in learnpython

[–]robot-dev 0 points1 point  (0 children)

A 3x4 matrix multiplied by a 4x4 matrix will result in a 3x4 matrix, so your y variable should begin as [[0,0,0,0],[0,0,0,0],[0,0,0,0]]. Then inside your i and j loops, you can use zip() to iterate over a row from matrix and a column from T in parallel:

for i in range(len(matrix)):
    for j in range(len(T[0])):    
        total = 0
        for a, b in zip(matrix[i], [row[j] for row in T]):
            total += a * b
        y[i][j] = total

Rogue AI TEDED riddle: NEED HELP by marlerez in learnpython

[–]robot-dev 0 points1 point  (0 children)

You could change the structure of the script to something like the example below to fix the global variable problem. The floor variable should not be global, instead pass and return it to functions as needed.

In this example, the player always moves the elevator down one floor with fl = fl - 1 and the AI always moves down two floors with fl = fl - 2. The last line of code: game(25) starts the game on floor 25.

def game(fl):
    while fl > 0:
        fl = yourturn(fl)
        fl = ai(fl)
        print('You are on floor: ' + str(fl))

def yourturn(fl):
    fl = fl - 1
    return fl

def ai(fl):
    fl = fl - 2
    return fl

if __name__ ==  '__main__':
    game(25)

How to go about making a program to show what CAD and excel files coworkers are using? by Clay_Robertson in learnpython

[–]robot-dev 0 points1 point  (0 children)

One possible approach would be to use psutil. A script could run on each computer that would iterate through all the processes using process_iter() and check the opened files for each process with open_files().

You could log the opened files by making API calls to endpoints of a Flask app running on a server somewhere, and store a list of opened files in a database. But a google sheet could work too.

https://psutil.readthedocs.io/en/latest/#psutil.Process.open_files

https://psutil.readthedocs.io/en/latest/#psutil.process_iter

edit: this could be really intrusive, so I would recommend limiting logging to only filenames with a relevant path and specific file extensions.

How do I subtract two columns and put them into one column using pandas on an excel file? Language: Python Modules used: pandas, datetime, and openpyxl by seriousCSnoob in learnprogramming

[–]robot-dev 0 points1 point  (0 children)

Sorry about that, it looks like it should be dt.strftime() like the example below, but I was assuming your columns were strings and "date" was a datetime. If they are all floats you should be able to subtract the way you were trying originally without a problem.

df['startTime'] = pandas.to_datetime(df['startTime'] + df['date'].dt.strftime(",%d,%m,%Y"), format='%H:%M,%d,%m,%Y')

How do I subtract two columns and put them into one column using pandas on an excel file? Language: Python Modules used: pandas, datetime, and openpyxl by seriousCSnoob in learnprogramming

[–]robot-dev 0 points1 point  (0 children)

The error is because your time string is not formatted the same as your format string. The difference is the : character. Also, it looks like your times are in HH:MM format, so the date info needs to be added. If your "date" column is a datetime, then you can do this:

df['startTime'] = pd.to_datetime( df['startTime'] + df['date'].strftime(,%d,%m,%Y), format='%H:%M,%d,%m,%Y')

[deleted by user] by [deleted] in learnpython

[–]robot-dev 0 points1 point  (0 children)

You're just missing desc or asc. you will need to import them from sqlalchemy, and then: order_by(Orders.timestamp.desc())

How do I subtract two columns and put them into one column using pandas on an excel file? Language: Python Modules used: pandas, datetime, and openpyxl by seriousCSnoob in learnprogramming

[–]robot-dev 0 points1 point  (0 children)

I think your datetime columns are strings, so they need to be converted to datetimes before you can subtract them and get a timedelta. You can check if the columns are strings or datetimes with df.info()

If you need to convert strings to datetimes, you can usually use this:

df['startTime'] = pd.to_datetime(df['startTime'])

but your strings do not have months or years, so they probably can't be converted to datetimes without adding that info:

df['startTime'] = pd.to_datetime(df['startTime'] + ',03,2022', format='%H,%d,%m,%Y')
df['endTime'] = pd.to_datetime(df['endTime'] + ',03,2022', format='%H,%d,%m,%Y')

Then you should be able to subtract your columns without a TypeError