python
import numpy as np
s = 46916
np.random.seed(s)
Z = np.random.randint(42,512,(48,12))
The random values in Z are supposed to be uniformly distributed from 42 to 512. This means there should be about the same number of items in the range 100-199 as there is 200-299. What is the absolute difference between the number of items in these ranges, inclusive of the upper and lower bound?
hint: np.histogram accepts bin limits as a list
import numpy as np
s = 46916
np.random.seed(s)
Z = np.random.randint(42,512,(48,12))
count,_=np.histogram(Z,bins=[4,100,200,300,400,512])
print(count)
absolute_diff=np.abs(count[1]-count[2])
print(absolute_diff)

python import numpy as np s = 46916 np.random.seed(s) Z = np.random.randint(42,512,(48,12)) The random values in...
Python import numpy as np import matplotlib.pyplot as plt Implement three different methods to simulate a Poisson process (No λ 0.1 on the time interval [0, 1001 with parameter For each method, plot a trajectory of your simulated process. 1. Method 1:use the exponentially distributed interarrial times
Python import numpy as np import matplotlib.pyplot as plt Implement three different methods to simulate a Poisson process (No λ 0.1 on the time interval [0, 1001 with parameter For each method, plot...
IN PYTHON 3 GIVING THIS CODE %matplotlib inline import numpy as np import matplotlib.pyplot as plt from sklearn import datasets N_samples = 2000 X = np.array(datasets.make_circles(n_samples=N_samples, noise=0.05, factor=0.3)[0]) plt.scatter(X[:,0], X[:,1], alpha=0.8, s=64, edgecolors='white'); Use Spectral Clustering to cluster the points and visualize your result
python
Problem 3-6 points First, start with the following code: import numpy as np A np.random. randint (0, 10, sie n,n)) np. savetxt ('exam2.txt', A, fmt-idelimiter B-# np. zeros ( (n, n) , dtypes, int 64, ) When run, it will produce a file named "exam2.txt" that has 5 rows each with 5 numbers separated by commas,. In addition, a 5 by 5 array of zeros named B is defined. Run this code, but do not change it Your job...
Hi. It's a python and I got an error below comment import numpy as np arr=np.genfromtxt("/Volumes/Samsung SSD 860 EVO 500GB Media/Download/primenumbers.txt", dtype=int) arr=arr.reshape(-1,1) arr.shape def find_cat(x): if x<= 300: return '<=300' elif x <= 600: return '<=600' else: return '<=1000' arr2 = np.apply_along_axis(find_cat, axis=1, arr=arr) arr2 = arr2.reshape(-1,1) arr3 = np.hstack((arr, arr2)) arr_300 = np.array((col[0] for col in arr3 if col[i]=='<=300'), dtype=int) arr_300 arr_300.shape count_300=len(arr_300) count_300 avg_300=round(np.mean(arr_300, 2) avg_300 print("Number of items in category \ "<=300\"= (one), and average of...
PYTHON
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
Our goal is to create a linear regression model to estimate
values of ln_price using ln_carat as the only feature. We will now
prepare the feature and label arrays.
"carat" "cut" "color"
"clarity" "depth" "table"
"price" "x" "y" "z"
"1" 0.23 "Ideal" "E" "SI2" 61.5 55 326
3.95 3.98 2.43
"2" 0.21 "Premium" "E" "SI1"...
do it in python 1. Import the proper libraries: Pandas and NumPy and create aliases pd, np respectively. 2. Load sample data (car_loan.csv) into data frame: df 3. Export Pandas DataFrames to csv. Save file name as out.csv. hint: help(df.to_csv) 4. Run the command: df.info (). What do you see, how many columns? also what about number of entries for each column 5. It is often the case where you change your column names or remove unnecessary columns. a. Change...
python
1
import matplotlib.pyplot as plt
2
import numpy as np
3
4
abscissa = np.arange(20)
5
plt.gca().set_prop_cycle(
’
color
’
, [
’
red
’
,
’
green
’
,
’
blue
’
,
’
black
’
])
6
7
class MyLine:
8
9
def __init__(self,
*
args,
**
options):
10
#TO DO: IMPLEMENT FUNCTION
11
pass
12
13
def draw(self):
14
plt.plot(abscissa,self.line(abscissa))
15
16
def get_line(self):
17
return "y = {0:.2f}x + {1:.2f}".format(self.slope,
self.intercept)
18
19
def __str__(self):...
You may import the following library functions in your module: from fractions import gcd from math import log from math import floor You may also use: • the .bit_length() method to efficiently obtain the bit length of an integer, • the abs() function for computing the absolute value of an integer, • and the // operator for integer division (you should avoid using / because it does not work for very large integers). Implement the following Python functions. These functions...
python / visual studio
Problem 1: Random Walk A random walk is a stochastic process. A stochastic process is a series of values that are not determined functionally, but probabilistically. The random walk is supposed to describe an inebriated person who, starting from the bar, intends to walk home, but because of intoxication instead randomly takes single steps either forward or backward, left or right. The person has no memory of any steps taken, so theoretically, the person shouldn't move...
Hi it's python I imported a data which are so many words in txt
and I arranged and reshaped with alphabetically both rows and
columns
I was successful with these steps but I am stuck with next
step
below is my code and screenshot
import numpy as np
import pandas as pd
data=pd.read_csv("/Users/superman/Downloads/words_file2.txt",header=None)
df_input=pd.DataFrame(data)
df_output=pd.DataFrame(np.arange(676).reshape((26,26)),
index =
['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'],
columns =
['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'])
df_output.index.name="Start"
df_output.columns.name="End"
df_output
This below screen shot is what I have to find
I have to find each word...