Element wise multiplication using Numpy [Python] [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I'm trying to get the element-wise mulitplication using normal *, and i tried np.multiply(), both give a weird answers.
now (1-y) is (100,) and np.log(1-sigmoid(np.dot(X,theta)))) is (100,1), so when i muliply them by element-wise, it should give (100,1); but it gives me (100,100) matrix(ALL are higlighted BLUE)
Here is my original function if it can help.
Can anyone help me with getting the source of erre here?

I'm not 100% sure why python does this, but the way to solve it would be to apply np.reshape((1-y),(100,1)) and then apply np.multiply(). In general it's always better to reshape your arrays and to give them a second dimension.
EDIT: This explains how numpy does the broadcasting when using an array of dimensions (n,) and (n,1).

Related

Converting H/T to 0/1 binary array [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last year.
Improve this question
I’ve loaded a sample using the code:
Data = np.load(sample_1.npy)
I need to convert the data points from H/T (coin tosses) to 0/1 (binary array). Not sure what code would work for this? I’ve tried googling answers and they haven’t worked.
If it's an array with "H" and "T" as values, you could try that:
Data = np.array([0 if x == "H" else 1 for x in Data])

Combining two array in python with np [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have two array one with shape (320,1) and one with (850,1) how should I combine the two array. I tried np.append however it seems to be an error.
Assuming the two arrays are called arr1 and arr2, you could try the following code:
arr3 = np.append(arr1,arr2).reshape((-1,1))
The reshape is needed to make sure the final shape is (1170,1) instead of (1170,)

Python Linear regression line error. how do i keep a straight line? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
For the above image, the regression lines are scribbled around and i don't know why? any help would be great.
I believe the issue here is that you are passing in data['size'], which is not sorted and goes between a value on the left and then to the right. The plt.plot always connects points, which is why you get squiggly line back and forth.
Now if this is a simple y = a + bx then I would recommend that you pass in an x input (e.g., x_range = [min(data['size']), max(data['size']) that is the minimum and maximum of data['size']. Then define yhat_no, yhat_yes, and yhat accordingly with x_range.
However, I see that you have a dependence data['year'], so the expectation of a single linear line will not happen.

How to calculate this mathematical expression in python? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I wanted to calculate this mathematical expression in python3:
Xi = (70 + 1344736401384689745317259585614247891453883777111/315)% 115792089210356248762697446949407573529996955224135760342422259061068512044369
But I'm getting this wrong result: 4.2690044488402846e+45 . Is there something wrong in the expression? how can I fix it to give me the right result?
I think you might be confused because it is showing scientific notation? '{}'.format() should help in that case.
Xi = (70 + 1344736401384689745317259585614247891453883777111/315)% 115792089210356248762697446949407573529996955224135760342422259061068512044369
print('{0:f}'.format(Xi))

OpenTurns Error when trying to use kernel build [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm getting the following error when I try to build my kernel.
Openturns error
Can anyone help?
The build only takes a Sample object. You have to convert your numpy array:
import openturns as ot
import numpy as np
sample = ot.Sample(np.array([(1.0, 2.0), (3.0, 4.0), (5.0, 6.0)]))
For the conversion to happen, your data need to have the proper shape: (n_sample, dimension)
In this example, we have 3 sample and the dimension is 2.

Categories

Resources