3

I have a numpy series of size (50,0)

array([1.01255569e+00, 1.04166667e+00, 1.07158165e+00, 1.10229277e+00,
       1.13430127e+00, 1.16387337e+00, 1.20365912e+00, 1.24007937e+00,
       1.27877238e+00, 1.31856540e+00, 1.35281385e+00, 1.40291807e+00,
       1.45180023e+00, 1.49700599e+00, 1.55183116e+00, 1.60051216e+00,
       1.66002656e+00, 1.73370319e+00, 1.80115274e+00, 1.87687688e+00,
       1.95312500e+00, 2.04750205e+00, 2.14961307e+00, 2.23613596e+00,
       2.34082397e+00, 2.48015873e+00, 2.61780105e+00, 2.75027503e+00,
       2.91715286e+00, 3.07881773e+00, 3.31564987e+00, 3.57142857e+00,
       3.81679389e+00, 4.17362270e+00, 4.51263538e+00, 4.95049505e+00,
       5.59284116e+00, 6.17283951e+00, 7.02247191e+00, 8.03858521e+00,
       9.72762646e+00, 1.17370892e+01, 1.47928994e+01, 2.10084034e+01,
       3.12500000e+01, 4.90196078e+01, 9.25925926e+01, 2.08333333e+02,
       5.00000000e+02, 1.25000000e+03])

And I have a pandas dataframe of length 50 as well.

            x
0   9.999740e-01
1   9.981870e-01
2   9.804506e-01
3   9.187764e-01
4   8.031568e-01
5   6.544660e-01
6   5.032716e-01
7   3.707446e-01
8   2.650768e-01
9   1.857835e-01
10  1.285488e-01
11  8.824506e-02
12  6.030141e-02
13  4.111080e-02
14  2.800453e-02
15  1.907999e-02
16  1.301045e-02
17  8.882996e-03
18  6.074386e-03
19  4.161024e-03
20  2.855636e-03
21  1.963543e-03
22  1.352791e-03
23  9.338596e-04
24  6.459459e-04
25  4.476854e-04
26  3.108912e-04
27  2.163201e-04
28  1.508106e-04
29  1.053430e-04
30  7.372442e-05
31  5.169401e-05
32  3.631486e-05
33  2.555852e-05
34  1.802129e-05
35  1.272995e-05
36  9.008454e-06
37  6.386289e-06
38  4.535381e-06
39  3.226546e-06
40  2.299394e-06
41  1.641469e-06
42  1.173785e-06
43  8.407618e-07
44  6.032249e-07
45  4.335110e-07
46  3.120531e-07
47  2.249870e-07
48  1.624726e-07
49  1.175140e-07

And I want to multiply every numpy cells with pandas cell.

Example:

1.01255569e+00*9.999740e-01
1.04166667e+00*9.981870e-01

Desired output

numpy array of same size.

3
  • 1
    Did you try anything? Commented Dec 9, 2018 at 1:09
  • I tried: p.multiply(n, axis=0) Commented Dec 9, 2018 at 1:09
  • Why not try *? Commented Dec 9, 2018 at 1:10

2 Answers 2

5

You can just use the .values property of the 'x' series in your Pandas dataframe:

df['x'].values * arr

where df is your dataframe and arr is your array.

The above expression will return the result as a Numpy array. If you want a Pandas DataFrame instead, you can omit the use of .values:

df['x'] * arr
Sign up to request clarification or add additional context in comments.

3 Comments

There is no need for .values here.
Thank you......Without the values, I get a series. With it, I get the array in the exact size.
@JohnZwinck Using .values makes the expression return a numpy array. Without it, you get a pandas dataframe. Whether you should use .values depends on which return type you want.
0

Or np.multiply, multiply n with p['x'].values:

print(np.multiply(n,p['x'].values))

Or pd.Series.multiply:

print(np.array(p['x'].multiply(n)))

Or pd.Series.mul:

print(np.array(p['x'].mul(n)))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.