Replacing Numerical Columns using pandas

I’m looking to replace the values of 2 specific columns (not including the header) of a data file that I have with randomly generated values. I already have the random values defined and now I’m looking to replace the columns of the original file with these new values. Each has 251 entries so it would be hard to identify each column individually.

import numpy as np import matplotlib.pyplot as plt import pandas as pd from pandas import DataFrame import os 

Loading my text file

X=np.asarray(np.loadtxt('/~/vh1/tdsw1.init',skiprows=1)).T 

Corresponding columns

Radius = X[1] R1=Radius+1 Velocity = X[2] Density = X[3] MVelocity = Velocity*(1+0.2*np.random.randn(len(Velocity))) MDensity = Density*(1+0.2*np.random.randn(len(Density))) 

Now I want to replace Velocity and Density with MVelocity and MDensity

data = pd.read_csv("/Users/dylanhilligoss/vh1/tdsw1MD.init",header=None) data.replace(to_replace=Velocity,value=MVelocity) data.replace(to_replace=Density,value=MDensity) print(data) 

The output is the exact same file that I originally called in. Does anyone have any suggestions?

Replacing a non-basepoint free line bundle by a basepoint free one

In his paper “Brill-noether-petri without degenerations”, Lazarsfeld says the following in in Corollary 1.4.

Statement – Assume that every member of the linear series $ |C_0|$ in a K3 surface is reduced and irreducible. Then for every smooth curve $ C$ in the linear system and every line bundle $ A$ on $ C $ , one has $ \rho(A)\geq 0$ where $ \rho(A)=g(C)-h^0(A)h^1(A)$ .

Proof: Let $ B$ be a special globally general line bundle on a smooth curve $ C$ . If $ B^*\otimes\omega_C$ has base divisor $ \Delta$ , then $ B(\Delta)$ is again basepoint free. Thus we can assume in the statement that both $ A$ and $ A^*\otimes \omega_C$ are globally generated.

I don’t understand the above.

1) First of all, how to prove that $ B(\Delta)$ is basepoint free?

2) Now $ B(\Delta)$ and $ \omega_C\otimes B^*(-\Delta)$ are globally generated. But how does that imply the statement for $ B$ ? In other words why is it enough to check for line bundles of the form $ B(\Delta)$ ?

3) In the proof of the main theorem, it says (from the above remark) if $ D$ is any effective divisor on $ C$ and $ \Delta$ is the divisor of basepoints of $ |D|$ , then the injectivity of the Petri map $ \mu_0$ for $ O_C(D-\Delta)$ implies the injectivity of $ \mu_0$ for $ O_C(D)$ ? Why is this?

Grateful for any help!

Refactoring: Replacing a temporary variable with a query. Is this code example bad practice?

Before I ask my question, I want to note that this is not my own code; it comes from the Refactoring Guru website:

enter image description here

I often find myself using the code on the left, and I have one primary motivation for doing so: in the code on the right, you are unnecessarily pushing and popping a stack frame for the same operation twice in a row. For example, suppose that the base price is in fact greater than 1000. In testing this conditional, you already computed what the base price is… So by the time you get to the body of that conditional, you already know the value, and there’s really no point in re-computing it with a second call to basePrice(). In either case—when the base price exceeds 1000 or is less than or equal to 1000—you end up with an extra redundant call to basePrice().

Question: Does the code on the right offer any real advantages over the one on the left? The site mentions that this allows for greater reusability of the code in case other methods want to compute the base price as well, which I agree with.

Refactoring: Replacing a temporary variable with a query. Is this code example bad practice?

Before I ask my question, I want to note that this is not my own code; it comes from the Refactoring Guru website (note that I’ve tagged this question as relating to C because I could not find a tag for refactoring/code cleanliness/style):

enter image description here

I often find myself using the code on the left, and I have one primary motivation for doing so: in the code on the right, you are unnecessarily pushing and popping a stack frame for the same operation twice in a row. For example, suppose that the base price is in fact greater than 1000. In testing this conditional, you already computed what the base price is… So by the time you get to the body of that conditional, you already know the value, and there’s really no point in re-computing it with a second call to basePrice(). In either case—when the base price exceeds 1000 or is less than or equal to 1000—you end up with an extra redundant call to basePrice().

Question: Does the code on the right offer any real advantages over the one on the left? The site mentions that this allows for greater reusability of the code in case other methods want to compute the base price as well, which I agree with.

Stern’s diatomic series fusc: replacing #define functions with two return values

I have a function to review which implements Stern’s diatomic series fusc for a single word (ulong = unsigned long) in place, as a part of an arbitrary-precision implementation. In fact, there’s just one part of it that’s bothering me, though I’d be happy to get feedback on any of it, of course.

I have a (pseudofunction) define fusc8bits which ‘returns’ two values. It works, but I’d rather do this some other way. As this is a performance-critical function any replacements will need to keep this requirement in mind. Alternatively, and unexpectedly, a reviewer might say that my approach is actually a good one.

Unfortunately the arrays are used by other functions, so they can’t be pulled inside the function. (I wish they weren’t so visually imposing, though.)

static const ulong fuscAA[] = {   1,  8,  7,  13, 6,  17, 11, 16, 5,  19, 14, 23, 9,  22, 13, 17, 4,  19, 15,   26, 11, 29, 18, 25, 7,  24, 17, 27, 10, 23, 13, 16, 3,  17, 14, 25, 11, 30,   19, 27, 8,  29, 21, 34, 13, 31, 18, 23, 5,  22, 17, 29, 12, 31, 19, 26, 7,   23, 16, 25, 9,  20, 11, 13, 2,  13, 11, 20, 9,  25, 16, 23, 7,  26, 19, 31,   12, 29, 17, 22, 5,  23, 18, 31, 13, 34, 21, 29, 8,  27, 19, 30, 11, 25, 14,   17, 3,  16, 13, 23, 10, 27, 17, 24, 7,  25, 18, 29, 11, 26, 15, 19, 4,  17,   13, 22, 9,  23, 14, 19, 5,  16, 11, 17, 6,  13, 7,  8,  1,  7,  6,  11, 5,   14, 9,  13, 4,  15, 11, 18, 7,  17, 10, 13, 3,  14, 11, 19, 8,  21, 13, 18,   5,  17, 12, 19, 7,  16, 9,  11, 2,  11, 9,  16, 7,  19, 12, 17, 5,  18, 13,   21, 8,  19, 11, 14, 3,  13, 10, 17, 7,  18, 11, 15, 4,  13, 9,  14, 5,  11,   6,  7,  1,  6,  5,  9,  4,  11, 7,  10, 3,  11, 8,  13, 5,  12, 7,  9,  2,   9,  7,  12, 5,  13, 8,  11, 3,  10, 7,  11, 4,  9,  5,  6,  1,  5,  4,  7,   3,  8,  5,  7,  2,  7,  5,  8,  3,  7,  4,  5,  1,  4,  3,  5,  2,  5,  3,   4,  1,  3,  2,  3,  1,  2,  1,  1 }; static const ulong fuscAB[] = {   8,  7,  13, 6,  17, 11, 16, 5,  19, 14, 23, 9,  22, 13, 17, 4,  19, 15, 26,   11, 29, 18, 25, 7,  24, 17, 27, 10, 23, 13, 16, 3,  17, 14, 25, 11, 30, 19,   27, 8,  29, 21, 34, 13, 31, 18, 23, 5,  22, 17, 29, 12, 31, 19, 26, 7,  23,   16, 25, 9,  20, 11, 13, 2,  13, 11, 20, 9,  25, 16, 23, 7,  26, 19, 31, 12,   29, 17, 22, 5,  23, 18, 31, 13, 34, 21, 29, 8,  27, 19, 30, 11, 25, 14, 17,   3,  16, 13, 23, 10, 27, 17, 24, 7,  25, 18, 29, 11, 26, 15, 19, 4,  17, 13,   22, 9,  23, 14, 19, 5,  16, 11, 17, 6,  13, 7,  8,  1,  7,  6,  11, 5,  14,   9,  13, 4,  15, 11, 18, 7,  17, 10, 13, 3,  14, 11, 19, 8,  21, 13, 18, 5,   17, 12, 19, 7,  16, 9,  11, 2,  11, 9,  16, 7,  19, 12, 17, 5,  18, 13, 21,   8,  19, 11, 14, 3,  13, 10, 17, 7,  18, 11, 15, 4,  13, 9,  14, 5,  11, 6,   7,  1,  6,  5,  9,  4,  11, 7,  10, 3,  11, 8,  13, 5,  12, 7,  9,  2,  9,   7,  12, 5,  13, 8,  11, 3,  10, 7,  11, 4,  9,  5,  6,  1,  5,  4,  7,  3,   8,  5,  7,  2,  7,  5,  8,  3,  7,  4,  5,  1,  4,  3,  5,  2,  5,  3,  4,   1,  3,  2,  3,  1,  2,  1,  1,  0 }; static const ulong fuscBA[] = {   0,  1,  1,  2,  1,  3,  2,  3,  1,  4,  3,  5,  2,  5,  3,  4,  1,  5,  4,   7,  3,  8,  5,  7,  2,  7,  5,  8,  3,  7,  4,  5,  1,  6,  5,  9,  4,  11,   7,  10, 3,  11, 8,  13, 5,  12, 7,  9,  2,  9,  7,  12, 5,  13, 8,  11, 3,   10, 7,  11, 4,  9,  5,  6,  1,  7,  6,  11, 5,  14, 9,  13, 4,  15, 11, 18,   7,  17, 10, 13, 3,  14, 11, 19, 8,  21, 13, 18, 5,  17, 12, 19, 7,  16, 9,   11, 2,  11, 9,  16, 7,  19, 12, 17, 5,  18, 13, 21, 8,  19, 11, 14, 3,  13,   10, 17, 7,  18, 11, 15, 4,  13, 9,  14, 5,  11, 6,  7,  1,  8,  7,  13, 6,   17, 11, 16, 5,  19, 14, 23, 9,  22, 13, 17, 4,  19, 15, 26, 11, 29, 18, 25,   7,  24, 17, 27, 10, 23, 13, 16, 3,  17, 14, 25, 11, 30, 19, 27, 8,  29, 21,   34, 13, 31, 18, 23, 5,  22, 17, 29, 12, 31, 19, 26, 7,  23, 16, 25, 9,  20,   11, 13, 2,  13, 11, 20, 9,  25, 16, 23, 7,  26, 19, 31, 12, 29, 17, 22, 5,   23, 18, 31, 13, 34, 21, 29, 8,  27, 19, 30, 11, 25, 14, 17, 3,  16, 13, 23,   10, 27, 17, 24, 7,  25, 18, 29, 11, 26, 15, 19, 4,  17, 13, 22, 9,  23, 14,   19, 5,  16, 11, 17, 6,  13, 7,  8 }; static const ulong fuscBB[] = {   1,  1,  2,  1,  3,  2,  3,  1,  4,  3,  5,  2,  5,  3,  4,  1,  5,  4,  7,   3,  8,  5,  7,  2,  7,  5,  8,  3,  7,  4,  5,  1,  6,  5,  9,  4,  11, 7,   10, 3,  11, 8,  13, 5,  12, 7,  9,  2,  9,  7,  12, 5,  13, 8,  11, 3,  10,   7,  11, 4,  9,  5,  6,  1,  7,  6,  11, 5,  14, 9,  13, 4,  15, 11, 18, 7,   17, 10, 13, 3,  14, 11, 19, 8,  21, 13, 18, 5,  17, 12, 19, 7,  16, 9,  11,   2,  11, 9,  16, 7,  19, 12, 17, 5,  18, 13, 21, 8,  19, 11, 14, 3,  13, 10,   17, 7,  18, 11, 15, 4,  13, 9,  14, 5,  11, 6,  7,  1,  8,  7,  13, 6,  17,   11, 16, 5,  19, 14, 23, 9,  22, 13, 17, 4,  19, 15, 26, 11, 29, 18, 25, 7,   24, 17, 27, 10, 23, 13, 16, 3,  17, 14, 25, 11, 30, 19, 27, 8,  29, 21, 34,   13, 31, 18, 23, 5,  22, 17, 29, 12, 31, 19, 26, 7,  23, 16, 25, 9,  20, 11,   13, 2,  13, 11, 20, 9,  25, 16, 23, 7,  26, 19, 31, 12, 29, 17, 22, 5,  23,   18, 31, 13, 34, 21, 29, 8,  27, 19, 30, 11, 25, 14, 17, 3,  16, 13, 23, 10,   27, 17, 24, 7,  25, 18, 29, 11, 26, 15, 19, 4,  17, 13, 22, 9,  23, 14, 19,   5,  16, 11, 17, 6,  13, 7,  8,  1 };  #define fusc8bits(a, b, idx)                                                   \   {                                                                            \     int i = (idx)&0xFF;                                                        \     int newA = a * fuscAA[i] + b * fuscAB[i];                                  \     b = a * fuscBA[i] + b * fuscBB[i];                                         \     a = newA;                                                                  \   } static void fusc_word(ulong u, ulong* a, ulong* b) {   *a = fuscAA[u & 0xFF];   *b = 0;   fusc8bits(*a, *b, u >> 8) fusc8bits(*a, *b, u >> 16)     fusc8bits(*a, *b, u >> 24) #ifdef LONG_IS_64BIT       fusc8bits(*a, *b, u >> 32) fusc8bits(*a, *b, u >> 40)         fusc8bits(*a, *b, u >> 48) fusc8bits(*a, *b, u >> 56) #endif } 

Asking opinion about replacing Windows 10 with Ubuntu

so basically I’m having an old HP laptop that has an Intel Pentium CPU N3700 @1.6GHz, has 4GB of RAM, 64-bit OS and runs Windows 10. I’m trying to replace that windows 10 with Ubuntu so I don’t if anyone that has experience about this can help me out. Thank you. It would be nice if anyone can share any good tutorial link for this. Please excuse my bad English.

Vertical lines on the left side of iphone 4s after it fell down. Can it be fixed without replacing its screen?

I accidentally dropped my iphone 4s and vertical lines have appeared on the left side. Although, the screen did not break. The screen works well but i can’t see the other side of the screen and i am struggling. Can it be fixed without the need to replace the screen? I tried to shut it down and open it it didn’t work. And i tried a method i saw on youtube where i would go to settings then ringtones and would play the ringtone and close and open the screen it did not work either. Please help me. Thank you

Is it possible to exploit XSS by replacing image data for img tag

If I have HTML page served over https with image loaded over http (image from other domain):

<img src="https://some-image.png"/> 

so it’s possible to inject any data to browser as image by using MITM attack. Is it possible to inject some Javascript code instead of image or maybe wrap some code to SVG image to execute this code in browser? Or the only risk is that someone can replace one image with another?

Replacing a specific users content creation with the newest version in views

enter image description here

I’m creating a website that tracks users weight. A user can create content to enter their weight and I have a view that displays all entries of a users weight however I want it so that if a user makes two entries on a single day that only the most recent from that day is shown and all the rest are not.

I have tried limiting the date but no success.