numpy

python plot intersection of line and data

蓝咒 提交于 2021-02-07 10:28:15
问题 I have a data file that looks something like this: 0 0 0.1 0.1 0.2 0.2 0.3 0.3 0.4 0.31 0.5 0.32 0.6 0.35 And I would like to find the the value that intersects with a slope. My code looks like this so far: from numpy import * from pylab import * data = loadtxt('test.dat') strain = data[:,0] stress = data[:,1] E = 1 y = [0, 0.5] x = 0.2, ((y[1] - y[0])/E+0.2) figure(num=None, figsize=(10, 6), dpi=100, facecolor='w', edgecolor='k') plot(strain, stress) plot(x, y) show() 回答1: You can use the

Solving Power Law Distribution in Python

此生再无相见时 提交于 2021-02-07 10:27:05
问题 I have data that closely resembles a power law distribution. Using Python, I want to approximate the data by solving two equations in the form: y is the y axis data. In Python it would be data[i] . x would be i + 1 . It follows that we get two equations with two unknown variables at the first data index and at a "random" 2nd one somewhere else in the data: The problem comes down to solving just due to mathematical simplification. I don't know how to solve an equation like this using libraries

Solving Power Law Distribution in Python

匆匆过客 提交于 2021-02-07 10:26:37
问题 I have data that closely resembles a power law distribution. Using Python, I want to approximate the data by solving two equations in the form: y is the y axis data. In Python it would be data[i] . x would be i + 1 . It follows that we get two equations with two unknown variables at the first data index and at a "random" 2nd one somewhere else in the data: The problem comes down to solving just due to mathematical simplification. I don't know how to solve an equation like this using libraries

Efficient transformation of gensim TransformedCorpus data to array

懵懂的女人 提交于 2021-02-07 10:13:30
问题 Is there a more direct or efficient method for getting the topic probabilities data from a gensim.interfaces.TransformedCorpus object into a numpy array (or alternatively, pandas dataframe) than the by-row method below? from gensim import models import numpy as np num_topics = 5 model = models.LdaMulticore(corpus, num_topics=num_topics, minimum_probability=0.0) all_topics = model.get_document_topics(corpus) num_docs = len(all_topics) lda_scores = np.empty([num_docs, num_topics]) for i in

Efficient transformation of gensim TransformedCorpus data to array

℡╲_俬逩灬. 提交于 2021-02-07 10:12:27
问题 Is there a more direct or efficient method for getting the topic probabilities data from a gensim.interfaces.TransformedCorpus object into a numpy array (or alternatively, pandas dataframe) than the by-row method below? from gensim import models import numpy as np num_topics = 5 model = models.LdaMulticore(corpus, num_topics=num_topics, minimum_probability=0.0) all_topics = model.get_document_topics(corpus) num_docs = len(all_topics) lda_scores = np.empty([num_docs, num_topics]) for i in

How can I find out if A * B is a Hadamard or Dot Product in Numpy?

天涯浪子 提交于 2021-02-07 10:08:33
问题 If I see the following line in a python code where numpy is imported: c = a * b What is the easiest and most practical way to determine if this operation is executed as a Hadamard (elementwise) or dot product (pointwise) operation? Is it right that for a Hadamard product the column and row size of A and B must be the same. For a dot product only the column size of A must be the same as the row size of B, correct? So I can lookup the shape of both and find out which operation is used? 回答1:

save multiple pd.DataFrames with hierarchy to hdf5

◇◆丶佛笑我妖孽 提交于 2021-02-07 09:48:30
问题 I have multiple pd.DataFrames which have hierarchical organization. Let's say I have: day_temperature_london_df = pd.DataFrame(...) night_temperature_london_df = pd.DataFrame(...) day_temperature_paris_df = pd.DataFrame(...) night_temperature_paris_df = pd.DataFrame(...) And I want to group them into hdf5 file so two of them go to group 'london' and two of others go to 'paris'. If I use h5py I lose the format of the pd.DataFrame , lose indexes and columns. f = h5py.File("temperature.h5", "w")

How to group all labels (index) which shares at least one “1” in the same column?

一笑奈何 提交于 2021-02-07 09:48:26
问题 Grouping Rules: has at least one "1" in the same column shares any number of rows in common (see example) For example: c0 c1 c2 c3 A 1 0 0 1 B 0 0 1 0 C 0 0 0 1 D 0 1 1 0 E 0 1 0 0 Expected output: [[A, C], [B, D, E]] As you can see B and E do not share "1" in columns, but they have "D" in common, therefore all 3 should be grouped 回答1: Here is a solution with networkx. import networkx as nx a = np.where(df.T, df.index, '').sum(axis=1) g = [list(x) for x in a if len(x) > 1] G = nx.Graph(g)

How to group all labels (index) which shares at least one “1” in the same column?

心不动则不痛 提交于 2021-02-07 09:47:32
问题 Grouping Rules: has at least one "1" in the same column shares any number of rows in common (see example) For example: c0 c1 c2 c3 A 1 0 0 1 B 0 0 1 0 C 0 0 0 1 D 0 1 1 0 E 0 1 0 0 Expected output: [[A, C], [B, D, E]] As you can see B and E do not share "1" in columns, but they have "D" in common, therefore all 3 should be grouped 回答1: Here is a solution with networkx. import networkx as nx a = np.where(df.T, df.index, '').sum(axis=1) g = [list(x) for x in a if len(x) > 1] G = nx.Graph(g)

IronPython unable to run script that imports numpy

家住魔仙堡 提交于 2021-02-07 09:36:28
问题 Disclaimer - I'm not familiar with Python. I'm a C# developer who has written an application to execute Python scripts (authored by others) using IronPython. These scripts have so far have only needed to use import math , but one of our users has asked for the application to support for Numpy. I have installed Numpy on my PC (using the 'numpy-1.9.2-win32-superpack-python2.7.exe' file), which has created a numpy folder under \Lib\site-packages. I've written a two-line Python script to test