Loading...
More Python Posts
import anytree as atimport random as rm# Generate a tree with node_count many nodes. Each has a number key that shows when it was made and a randomly selected color, red or white.def random_tree(node_count):# Generates the list of nodesnodes = []for i in range(node_count):test = rm.randint(1,2)if test == 1:nodes.append(at.Node(str(i),color="white"))else:nodes.append(at.Node(str(i),color="red"))#Creates the various main branchesfor i in range(node_count):for j in range(i, len(nodes)):test = rm.randint(1,len(nodes))if test == 1 and nodes[j].parent == None and (not nodes[i] == nodes[j]):nodes[j].parent = nodes[i]#Collects all the main branches into a single tree with the first node being the rootfor i in range(1, node_count):if nodes[i].parent == None and (not nodes[i] == nodes[0]):nodes[i].parent = nodes[0]return nodes[0]
# Input for row and columnR = int(input())C = int(input())# Using list comprehension for inputmatrix = [[int(input()) for x in range (C)] for y in range(R)]
import subprocess #for the praat callsimport os #for ffmpeg and the pause call at the end#Even if we wanted all videos being rendered asynchronously, we couldn't see progress or errorsimport glob #for the ambiguous filesimport tempfileaudioFileDirectory = 'Audio Files'timeList = {}fileList = glob.glob(audioFileDirectory + '\\*.wav')pipeList = {}for fileName in fileList:arglist = ['Praat.exe', '--run', 'crosscorrelateMatch.praat', 'zeussound.wav', fileName, "0" , "300"]print(' '.join(arglist))pipe = subprocess.Popen(arglist, stdout=subprocess.PIPE)pipeList[fileName[len(audioFileDirectory)+1:-4]] = pipe #+1 because of back slash, -4 because .wav#for fileName, pipe in pipeList.items():# text = pipe.communicate()[0].decode('utf-8')# timeList[fileName] = float(text[::2])for fileName, pipe in pipeList.items():if float(pipe.communicate()[0].decode('utf-8')[::2]) > .0003: #.000166 is not a match, and .00073 is a perfect match. .00053 is a tested matcharglist = ['Praat.exe', '--run', 'crosscorrelate.praat', 'zeussound.wav', audioFileDirectory + '\\' + fileName + '.wav', "0" , "300"]print(' '.join(arglist))text = subprocess.Popen(arglist, stdout=subprocess.PIPE).communicate()[0].decode('utf-8')timeList[fileName] = float(text[::2])clipLength = 10for fileName, time in timeList.items():arglist = ['ffmpeg', '-i', '"'+fileName+'.mp4"', '-ss', str(time-clipLength), '-t', str(clipLength*2), '-acodec', 'copy' , '-vcodec', 'copy', '"ZEUS'+ fileName + '.mp4"']print(' '.join(arglist))os.system(' '.join(arglist))tempFile = tempfile.NamedTemporaryFile(delete=False)for fileName in glob.glob('ZEUS*.mp4'):tempFile.write(("file '" + os.path.realpath(fileName) + "'\n").encode());tempFile.seek(0)print(tempFile.read())tempFile.close()arglist = ['ffmpeg', '-safe', '0', '-f', 'concat', '-i', '"'+tempFile.name+'"', '-c', 'copy', 'ZeusMontage.mp4']print(' '.join(arglist))os.system(' '.join(arglist))os.unlink(tempFile.name) #Delete the temp file#print(timeList)os.system('PAUSE')
bytes_data = b'Hello, World!'string_data = bytes_data.decode('utf-8')print("String:", string_data)
print("test")
# Function to multiply two matricesdef multiply_matrices(matrix1, matrix2):# Check if the matrices can be multipliedif len(matrix1[0]) != len(matrix2):print("Error: The number of columns in the first matrix must be equal to the number of rows in the second matrix.")return None# Create the result matrix filled with zerosresult = [[0 for _ in range(len(matrix2[0]))] for _ in range(len(matrix1))]# Perform matrix multiplicationfor i in range(len(matrix1)):for j in range(len(matrix2[0])):for k in range(len(matrix2)):result[i][j] += matrix1[i][k] * matrix2[k][j]return result# Example matricesmatrix1 = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]matrix2 = [[10, 11],[12, 13],[14, 15]]# Multiply the matricesresult_matrix = multiply_matrices(matrix1, matrix2)# Display the resultif result_matrix is not None:print("Result:")for row in result_matrix:print(row)