Ornaments in baroque music: should be avoided in some cases?

Question: In baroque music, often the performers add ornaments (or even more complex variations) to the written notes, mostly during a repeat. It's very common to hear them on Bach, Vivaldi, Marcello, etc...
This is especially true for the solo part of a concerto, but often it happens even for the harpsichord/piano execution of keyboard music.
Surprisingly, it seems it's not a common practice for some composers or pieces. At least, I've never heard that for Galuppi's or Paradisi's sonatas, for example. It's just me or is there an explanation for this?
Comment: "At least, I've never heard that for Galuppi's or Paradisi's sonatas, for example": have you heard recordings by baroque music specialists of these pieces?  They're not widely performed, so my first guess is that the performances you've heard were by musicians who also don't ornament pieces by Bach or Scarlatti.
Comment: Yeah okay, having heard (a few seconds of each of) those recordings I'm going to say it's probably because of the later compositional style.  They sound more like Haydn or Mozart even though the composers are closer in time to Bach and Scarlatti.  Modern performance practice places less emphasis on ornamentation of classical-period music than baroque, rightly or wrongly.
Comment: There are a lot of period primary sources about when and how to ornament. The best approach is to try to get a more focused rule set than "all of the baroque"; e.g. can you narrow in on a century or less, and maybe on a specific instrumental practice? (E.g. flute might "import" some vocal ornamentation practices, but not necessarily all of them.) Also, remember that comments aren't part of the question; they're more temporary. If you want to clarify or add to your question, please use the "Edit" button.
Comment: Maybe. Two examples: https://youtu.be/E4ZoJ2RDhTE and https://youtu.be/sRVg_qqcRSw. If I'm not wrong, the repeats are pretty similar, compared to the usual variations I hear on, say, English Suites of Bach (i.e. https://youtu.be/drHrf3qbpQY)
Comment: Understood, thanks. Last question: is it therefore inadvisable to add them or is it at the discretion of the executor? I speak especially for the two examples I have given
Answer: Ornamentation such as you describe was undoubtedly common practice during the baroque period and even later (Robert Levin's lectures on Mozart and improvisation, available on Youtube, are highly enlightening, see here).
The degree to which one adds non-written ornaments (either on repeats or at other places in the piece where they might be needed) depends on various factors. Some pieces, for example, already have highly ornamented musical lines and adding more would be simply too much. One criticism levelled at Bach (examples abound, both in vocal - for ex. the duets in BWV 140; notice both the highly ornamented violin line and the notated vocal ornaments - and instrumental works) by Johann Scheibe, a contemporary critic, was that he did just that, leaving little place for creativity (cf. Barber, 1971, amongst many sources on the topic).
Other factors include the performer's technical ability and experience with such improvisation, and, most importantly, what feels musically appropriate (one could term this "good taste") at the particular point in the piece. As Levin says, the purpose of decoration is "to deepen to expression of the piece, not to show off your finger virtuosity". What constitutes "good taste" at any given point, of course, is a matter for personal interpretation by the performer, and in any case, is where the crux of the matter probably lies. Add to that geographical differences in music interpretation (back in the baroque period and even nowadays), and you have a perfect recipe for exactly the kind of difference you mention in your question.


Drilling down into an Entity Reference Field in Rules Actions

Question: I have the following setup where I have 2 content types called BRIEFS and IDEAS. On BRIEFS, I have a list of users selected in a field called brief_recipients which is a user reference field.
IDEAS has a entity reference field (associated_brief) that references a BRIEF.
Currently when I create an IDEA, it will email the author of the referenced BRIEF. This works using the following rules setup:

Now I'm trying to add in a LOOP to access the entityfield associated_brief's > brief_recipients field and email them too.
But the problem seems to be that Rules cannot drill down into an entityfield's fields as I can only get to body and author only as seen here:

Now the question is how do you drill down into an entity field's fields? Or is there another suggested way of doing this?
Which hook would I need to tap into if I had to write this custom?
Comment: Best to stick to one question.
Answer: In my scattered experience with rules, a limitation on what data you can access is usually a safeguard because the data has not been confirmed to exist yet.  In the Rules conditions, create "entity has field" condition twice.
1) Rule Conditions > Entity has field
Data selector: node
Field: field-associated-brief
This is your entity reference field, and gives Rules the comfort of knowing the reference field is usable. Once you have the above conditions, rules will load up the referenced fields from your node
2) Rule Conditions > Entity has field
Data selector: node:field-associated-brief
Field: field-breif-recipients
3) Now the action is able to use the field confirmed in the conditions
Even if you do not think the conditions should be required, it is good practice to confirm you have the data before you try to use it.  Here is another person who had a very similar issue
Comment: ok that works! just tried it by adding in the field and **selecting** via the dropdown the target field to expose. screenshot: http://prntscr.com/86929p
Comment: Now how would one get the node path of that referenced entity? i want to put that in the body of email message.
Comment: nvm i got it! you just have to do the same thing but this type select **Entity as Node** from the drop down.


All tasks in the Task Scheduler stop triggering until I restart the server (W.Server 2008 Datacenter)

Question: First of all, some info:

Windows Server 2008 Datacenter, 100% updated with Service Pack 2 and all the patches.
I connect to it using "Remote Desktop Connection" (I don't now if this is relevant)
I login using a user that is an administrator

The tasks in the Task Scheduler get triggered for a few days, then they don't do until I restart the operating system. Then they work again for a few days and stop, and so on.
When I open the Task Scheduler administrator, select any of the tasks, and the open the "history" tab below, I don't see any entries for the last events that should have happened, but didn't. I mean, no entries at all that would indicate that the task triggered or tried to trigger. In other words, as if the task had been totally ignored by the scheduler. All tasks seem to suffer the same.
When I open the Event Viewer, I don't see any useful information. No entries at all for all those events that never happened, no system error indications, nothing. I have checked all the relevant directories in the event viewer (the 5 windows logs and the "....\Microsoft\Windows\TaskScheduler" log. Nothing there that would explain what is wrong.
The "Task Scheduler" service started, thats for sure because the events happen for some time until they stop. Then, when they don't run anymore, I assume the service is still running but I'm not 100% sure because for some reason the stop/pause/restart/..../start commands in this service seem to be disabled (I don't know why), even though I have logged in as an administrator, so I can not try restarting the service so see of the events work again.
All other functions in the operating system seem to work fine, the RAM amount is fine, the server doesn't get unresponsive or any other bad symphtom.
Does anybody know what is the problem? I have been strugling with this failure for a long time, a year or more having to restart my server every few days.
Thanks in advance!
Comment: What kind of triggers are you using for these tasks?
Comment: I have the same issue. Even when the task is Run manually, nothing at all shows up in the task history, as if it didn't even try to run the task. It's not security context either.
Answer: What stands out to me in your question is "...they work again for a few days and stop...".  In my experience, these types of issues are usually related to security context.
Check to make sure the "Run whether user is logged on or not." radio button is checked.  I would first suspect that you're logging in as the administrative user that the task runs under, and it's fine until your session is terminated.
If that is set properly, then check to make sure the task conditions (in Task Properties) are able to be met consistently.
Answer: Do you have Windows Live installed? I was pulling my hair out over this, but then found if you disable the Windows Live \ SOXE task everything comes back to life
http://social.msdn.microsoft.com/Forums/en/winserver2008appcompatabilityandcertification/thread/6fa3c7fa-511b-498d-9b37-1201e1ff2e59


Machine Learning + Hyperparameter Tuning + Data Leakage : Is my procedure free of data leakage?

Question: I'm trying to classify 8 types of hand gestures with EMG signals. For that I followed these steps:

Split the entire data into training data and test data
For training data I extracted features. Here how I did that: The training dataset contains 8 files. Each file consists of 50 readings of the Myo armband for a defined gesture. Each reading includes 100 samples per sensor. There are 8 sensors. For every 100 samples/sensor, Mean (of) Absolute Values (MAV) is computed. For 8 sensors, 8 MAVS are computed for a reading. So every row contains 8 MAV values for a particular gesture. Here's a subset of training data (last column is the respective gesture number):

After that I tried to test several ensemble models as classifiers on the training data. For an instance, I tried to use stack of Random Forest, KNN, SVM on the training data. For that I used GridSearchCV for hyper-parameter tuning(I didn't use pipelie). Here's the code:
param_grid = [
    {
        #Random forest
        'bootstrap': [True, False],
        'max_depth': [40, 50, 60, 70, 80],
        #'max_features': [2, 3],
        'min_samples_leaf': [3, 4, 5],
        'min_samples_split': [8, 10, 12],
        'n_estimators': [10, 15, 20, 25],
        'criterion' : ['gini', 'entropy'],
        'random_state' : [45]
    },

    {
        #K Nearest Neighbours
        'n_neighbors':[5,6,7,9,11],
        'leaf_size':[1,3,5,7],
        'algorithm':['auto', 'ball_tree', 'kd_tree', 'brute'],
        'metric':['euclidean', 'manhattan']

    },

    {
        #SVM
        'C': list(np.arange(1, 5, 0.01)),
        'gamma': ['scale', 'auto'],
        'kernel': ['rbf', 'poly', 'sigmoid', 'linear'],
        'decision_function_shape': ['ovo', 'ovr'],
        'random_state' : [45]
    }
]

models_to_train = [RandomForestClassifier(), KNeighborsClassifier(), svm.SVC()]

final_models = []
for i, model in enumerate(models_to_train):
    params = param_grid[i]

    clf = GridSearchCV(estimator=model, param_grid=params, cv=20, scoring = 'accuracy').fit(data_train, label_train)
    final_models.append(clf.best_estimator_)

Did similar feature extraction procedure like step 2 for test data

Fit the stacked model to the training data, made prediction on test data and calculated accuracy.

estimators = [
    ('rf', final_models[0]),
    ('knn', final_models[1])
]
clf = StackingClassifier(
    estimators=estimators, final_estimator=final_models[2]
)

category_predicted = clf.fit(data_train, label_train).predict(data_test)

acc = accuracy_score(label_test, category_predicted) * 100

Now, my question is,

Is there any chance of data leakage in this procedure?

Edit
I believe this procedure suffers from data leakage because I did feature extraction in step 2 on entire training data and those features are used in GridSearchCV without any pipeline . If I put feature extraction (what described in step 2) and estimator in pipeline (as discussed here: https://towardsdatascience.com/pre-process-data-with-pipeline-to-prevent-data-leakage-during-cross-validation-e3442cca7fdc), then it can be avoided.
Comment: I'm not completely sure what you mean by "MAV" in your Step 2, where you say that you did feature extraction. Please provide more details on that.
Comment: I added definition of MAV (Mean (of) Absolute Values) in question.
Answer: A potentially bigger problem than data leakage between test and training sets is the unreliability of test/train splits of small data sets. You need many thousands of cases for that to be reliable. Otherwise you are throwing away information by limiting the size of the training set, and you are getting imprecise estimates of model validity by having too small a test set.
As you have a well-defined algorithm for building your model, consider internal validation by bootstrapping instead. This answer outlines the procedure. Even if you continue to use a train/test split for your modeling, repeating the entire modeling process including the original train/test split on multiple bootstrap samples of your data will evaluate how much of a problem is imposed by any data leakage.
In your case you don't appear to have a problem with data leak in your cross validation. All you have done is to combine raw readings into a type of average, the MAV, without any attempt to standardize the readings within each sensor at that point of the analysis. There might be some standardization later on within your parameter search, but so far as I can tell (I'm not fluent in sklearn) that seems to be done appropriately.
That's different from the situation described in the page you link. There each of the predictors was standardized from the beginning to put them on the same relative scale, as is needed for principal-component analyses and penalized regressions (ridge, LASSO). As the degree of transformation of any predictor needed for the standardization will vary from sample to sample, that can be a problem if your (wise) intent is to repeat the entire modeling process (including the standardization) in each CV fold or bootstrap sample. You haven't fed your parameter search pre-standardized data, just an average without any change of scale, so you shouldn't have that problem.
Comment: @Debbie I'd recommend a different approach. Use GridSearchCV on the whole data set to choose hyper-parameters and build the full model: no test/train split. Then set up your bootstrapped re-samples, and do the GridSearchCV and model building on each of the re-samples. On each of the re-samples you have the advantages you found with GridSearchCV. Then test each of the resulting models on the full data set. This estimates the quality of the modeling process, including the GridSearchCV, without a fixed test/train split. See [this page](https://stats.stackexchange.com/a/484202/28500).
Comment: I found an implementation of Bootstrap CV here : https://www.kaggle.com/sasha18/resampling-methods-using-bootstrap-cv

But is it possible (or practically feasible) to tune huge number of hyper-parameters with Bootstrap CV which I did easily with GridSearchCV?


Como resolver Fatal error: Call to undefined function ContaUsuario() in

Question: No meu caso eu tenho essa função :
no arquivo Home bem no inicio importei aqui:
    <?php

      require_once("session.php");

      require_once("class_usuario.php");
      $auth_user = new USER();

      $user_id = $_SESSION['user_session'];

      $stmt = $auth_user->runQuery("SELECT * FROM N00_Usuario WHERE idUsuario=:user_id");
      $stmt->execute(array(":user_id"=>$user_id));

      $userRow=$stmt->fetch(PDO::FETCH_ASSOC);

    ?>

    e no arquivo Home importei a classe que está dentro do arquivo Class_usuario:
    <?php

      require_once("session.php");

      require_once("class_usuario.php");
      $auth_user = new USER();

      $user_id = $_SESSION['user_session'];

      $stmt = $auth_user->runQuery("SELECT * FROM N00_Usuario WHERE idUsuario=:user_id");
      $stmt->execute(array(":user_id"=>$user_id));

      $userRow=$stmt->fetch(PDO::FETCH_ASSOC);

    ?>

                  <?php

                  try{
                    $a= ContaUsuario($connection) ;
                  }

                catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}
                  ?>

<?php echo $a;?>

Page views

o que tem de errado?Alguém tem uma ideia?
Answer: Utilize sua classe e chame o método.
try{
      $result =  $auth_user->ContaUsuario($connection);

<?php echo $result;?>

 }

Comment: @Gladiador marque como respondida , isso ajuda a comunidade e outras pessoas que forem ver a questão.
Comment: eu vou tentar para ver o que dá @Felipe
Comment: Caso não funcione publique aqui, que tento achar outra forma. @Gladiador
Comment: Então @Felipe o erro contiua. Talvez pq expliquei errado. a função está em um outro arquivo chamado Class_Usuario e a parte  também está em um outro arquivo Home. Estou querendo lista o numero total de usuario cadastrado
Comment: Você importou o arquivo Class_Usuario? Tem como postar o codigo de Class_Usuario? @Gladiador
Se for uma classe php você deve instanciar um objeto da classe e chamar o metodo.

`$obj = new Class_Usuario();
$rows = $obj.ContaUsuario($connection);  `
Comment: acabei de postar o código . editei para você ver e se consegue ver algo de errado.
Comment: O que você postou é só o código do arquivo Home? @Gladiador
Comment: postei os dois camarada. em cima é da class_usuario e no final e do Home
Comment: Vamos [continuar esta discussão no chat](http://chat.stackexchange.com/rooms/68780/discussion-between-felipe-and-gladiador).


segment fault after parsing unsigned char to int pointer

Question: I'm facing a problem when trying to read a binary file of fixed size. The code below returns segmentation Fault just before closing the file. What I want to achieve it is to return an int pointer back to the main function.
The file it s a raw grayscale image, which has values from 0 to 255, that's why I'm using unsigned char.
How can I convert and assign from unsigned char to *int properly?
Any kind of help will be welcome!
void readBinaryFile(char *filename, int *in){

    FILE *file;
    long length;
    unsigned char *imagen;

    int c;

    file = fopen(filename, "rb");
    fseek(file,0,SEEK_END);
    length = ftell(file);

    imagen = (unsigned char *) malloc(length);
    fseek(file, 0, SEEK_SET);
    fread(imagen, length,  1 , file);

    int cont;
    //c+4: file contains values from 0 to 255
    for(c=0,cont=0;c<length;c=c+4,cont++){
       in[cont] = (unsigned char) imagen[c];
    }

    for(cont=0;cont<length/4;cont++){
       printf("%d",(int) in[cont]);
    }

    fclose(archivo);
    free(imagen_buffer);
}

void main(int argc, char **argv){

    int *in;
    int fixed_size = 784;
    in = (int *) malloc((fixed_size)*(fixed_size));
    readBinaryFile("test.raw", in);

    int c;

    for(c=0;c<((fixed_size)*(fixed_size));c++){
        printf("%d", (unsigned char) in[c]);
    }
}

Answer: This
int *in;

makes in point to an int.
This
 in = (int *) malloc((fixed_size)*(fixed_size));

allocates to in 784*784=614656 bytes.

You need 784*784 ints.
An int needs sizeof (int) bytes, which by definition is very well might be and most often is larger then 1.

From 1. and 2. above it can be deduces that 784*784 int needs more then 784*784 bytes.
So change
in = (int *) malloc((fixed_size)*(fixed_size));

to be
in = (int *) malloc((fixed_size)*(fixed_size) * sizeof (int));

or even nicer and safer with less noise do
in = malloc(fixed_size*fixed_size * sizeof *in);

because

in C there is no need to cast void* (which malloc() returns).
the parentheses around fixed_size are useless.
using sizeof *in returns the same as sizeof (int), but would "survive" if you changed int * in to become for example unsigned * in.

Also while reading you need to make sure to not read more then 784*784  char, as else the memory allocated for the int will be overflowed, which in turn invoked the infamous Undefined Behaviour.
Comment: dude,  I was stuck in this like all night, THANKS !
Comment: The size of `int` is not more than one by definition. It would have to be a derived property, as there is no such definition. However, by extensive discussion elsewhere on Stack Overflow, it may be possible for a conforming implementation to have `int` and `char` be the same size. (`EOF` is a troublesome issue for that.)
Comment: @EricPostpischil "*possible ...  to have `int` and `char` be the same size*" Really? I memorise the C Standard defining `CHAR_MAX` to be 127 or 255 as maximum and `INT_MAX` to be 32767 as minimum. Mind sharing the link to the discussion you mention?
Comment: @alk: The standard does not limit `CHAR_MAX` to being 127 or 255. There is discussion in [this question](https://stackoverflow.com/questions/3860943/can-sizeofint-ever-be-1-on-a-hosted-implementation).
Comment: @EricPostpischil Oh, yes I see: Only the minimum values are defined by the Standard. My bad. Thank you for the correction.


Pyinstaller cannot compile project with sklearn

Question: I'm trying to compile this simple python 3 (pyconda) machine learning project with sklearn and these imports (it's a simple Ridge regression predictor):
from datetime import date
import pandas as pd
import numpy as np
from sklearn.linear_model import Ridge

pd.options.mode.chained_assignment = None

class covidUpdater:
    situazione = ""

    def getCovidUpdate(self):
        url = "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-andamento-nazionale/dpc-covid19-ita-andamento-nazionale.csv"
        ds = pd.read_csv(url)
        return ds.tail(self.giorni)

    def __init__(self):
        pass

    def setGiorni(self,giorni):
        self.giorni = giorni
        self.situazione = self.getCovidUpdate()

    def getCampo(self,campo):
        return self.situazione[[campo]]

    def getMaxLength(self):
        ur1l = "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-andamento-nazionale/dpc-covid19-ita-andamento-nazionale.csv"
        ds1 = pd.read_csv(ur1l)
        return len(ds1)

    def formatTable(self,campo):
        giorniPrediction = 1
        updater = covidUpdater()
        updater.setGiorni(self.giorni)
        updaterFuture = covidUpdater()
        updaterFuture.setGiorni(self.giorni+giorniPrediction)
        datiCampo = updater.getCampo(campo)
        datiCampoFuture = updaterFuture.getCampo(campo)
        campo_domani = str(campo) + "_domani"
        datiCampo[campo_domani] = datiCampoFuture.shift(-giorniPrediction)
        datiCampo = datiCampo.head(self.giorni-giorniPrediction)
        datiCampo["id"] = range(datiCampo.iloc[:, 0].size)
        return datiCampo

def main():
    campo = "nuovi_positivi"
    updater = covidUpdater()
    giorni = int(input("Inserisci numero giorni da usare come dataset> ") or updater.getMaxLength())
    updater.setGiorni(giorni)
    print("Giorni selezionati: ",giorni)
    df = updater.formatTable(campo)

    print("Imposto l'algoritmo di predizione")
    X = df.iloc[:, 0].values.reshape(-1,1)
    Y = df.iloc[:, 1].values.reshape(-1,1)
    regr = Ridge(alpha=1.0,normalize=False,tol=0.1,solver="lsqr")

    print("Avvio l'algoritmo di predizione")
    regr.fit(X,Y)
    Y_pred = regr.predict(X)

    print("-----------------------------------\n")
    print("Giorni in esame: "+ str(giorni)+"\n")
    print("Predizione di (" + str(date.today()) + ") : "+ str(regr.predict(np.array([Y[Y.size-1]])))+"\n")
    print("fattore R2: "+ str(regr.score(Y,Y_pred))+"\n")
    print("-----------------------------------"+"\n")

if __name__ == "__main__":
   main()

By using this command:
pyinstaller --noconfirm --onedir --console --hidden-import "sklearn.linear_model.Ridge"  "PATH"

I have this log the final error is:
Traceback
Traceback (most recent call last):
  File "d:\pyconda\lib\site-packages\auto_py_to_exe\packaging.py", line 131, in package
    run_pyinstaller()
  File "d:\pyconda\lib\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "d:\pyconda\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "d:\pyconda\lib\site-packages\PyInstaller\building\build_main.py", line 720, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "d:\pyconda\lib\site-packages\PyInstaller\building\build_main.py", line 667, in build
    exec(code, spec_namespace)
  File "C:\Users\Alex\AppData\Local\Temp\tmp854ytoyk\covid2.spec", line 17, in <module>
    noarchive=False)
  File "d:\pyconda\lib\site-packages\PyInstaller\building\build_main.py", line 242, in __init__
    self.__postinit__()
  File "d:\pyconda\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
    self.assemble()
  File "d:\pyconda\lib\site-packages\PyInstaller\building\build_main.py", line 419, in assemble
    self.graph.process_post_graph_hooks()
  File "d:\pyconda\lib\site-packages\PyInstaller\depend\analysis.py", line 365, in process_post_graph_hooks
    module_hook.post_graph()
  File "d:\pyconda\lib\site-packages\PyInstaller\depend\imphook.py", line 440, in post_graph
    self._load_hook_module()
  File "d:\pyconda\lib\site-packages\PyInstaller\depend\imphook.py", line 407, in _load_hook_module
    self.hook_module_name, self.hook_filename)
  File "d:\pyconda\lib\site-packages\PyInstaller\compat.py", line 588, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 407, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 907, in load_module
  File "<frozen importlib._bootstrap_external>", line 732, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "d:\pyconda\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-zmq.py", line 21, in <module>
    hiddenimports = ['zmq.utils.garbage'] + collect_submodules('zmq.backend')
  File "d:\pyconda\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 595, in collect_submodules
    repr(pkg_dir), package))
  File "d:\pyconda\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 79, in exec_statement
    return __exec_python_cmd(cmd)
  File "d:\pyconda\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 68, in __exec_python_cmd
    txt = exec_python(*cmd, env=pp_env)
  File "d:\pyconda\lib\site-packages\PyInstaller\compat.py", line 521, in exec_python
    return exec_command(*cmdargs, **kwargs)
  File "d:\pyconda\lib\site-packages\PyInstaller\compat.py", line 316, in exec_command
    out = out.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 112: invalid start byte

Full log here: https://pastebin.com/XuBeLz3X
Answer: I think you should start with the first error in the log:
3560572 INFO: Analyzing hidden import 'sklearn.linear_model.Ridge'
3560576 ERROR: Hidden import 'sklearn.linear_model.Ridge' not found

Have you had a look at this thread with the Hidden import error? How do you resolve 'hidden imports not found!' warnings in pyinstaller for scipy?
I think you need to adjust your hidden imports, so that 'sklearn.linear_model.Ridge' can be found.
And I just tried running your code in Google Colab (https://colab.research.google.com/) and it works there. Perhaps you can run your code there?
Comment: The code itself compiles, i was trying to develop a standalone to send to one of my friends. Is there an alternative than using pyinstaller to create a machine learning standalone?


Problem creating path alias in code

Question: I am creating a node and a path alias roughly as follows:
<?php
$node = (object) array( 'type' => 'article');
node_object_prepare($node);
$node_wrapper = entity_metadata_wrapper('node', $node);
// ... some more fields get set here...
$node_wrapper->title->set( 'Foo' );
$node_wrapper->save();

// Set the path
$path = array(
  'source' => "node/$node->nid",
  'alias' => "foo/bar",
);
path_save($path);

The node is created OK, and the path seems to be created OK, too. I can type foo/bar in as the path and I see the new blank page. However when I edit that page, the Path Alias is blank?!
I have pathauto installed - could this be something to do with it? Nb. when I edit the page the "Generate path automatically" pathauto checkbox is not checked (which is what I'd expect).
Answer: Inspecting the differences in the node table, I noticed that the node created by my code had an empty language field. Updating this to "und" fixed the node alias.
This makes sense, because path_save() defaults to LANGUAGE_NONE (i.e. "und").
I had assumed that node_prepare would do likewise, but it does not.
So the solution is to set $node->language = LANGUAGE_NONE; at the point of creation.
Also, this is an easier way to create the alias...
$node->path = array('alias' => $path, 'pathauto' => FALSE);

Comment: Using `$node = entity_create('node', array('type' => 'article'));` should take care of the language thing.  Off the top of my head I can't remember if it also takes care of the `node_object_prepare()`.
Comment: Ours is a multilingual site so certainly have to select English for it and still seeing this issue

Problem creating path alias in code


Maximising the area of a triangle with its vertices on a parabola.

Question:
Let $A\equiv (4,-4)$ and $B\equiv(9,6)$ be tw points on the parabola $y^2 = 4x$. Let $C$ be a point on the parabola between $A$ and $B$ such that the area of the triangle $\triangle ABC$ is maximal. What are the coordinates of $C$?

The  parametric coordinates of C are $(t^2 , 2t)$. Using Shoelace formula, I get the area of the triangle to be $5t^2 -5t$. But this has no global maximum? In this case, what shluld I do?
Comment: You could think geometrically, and show that the area is maximal when the tangent to the parabola at $C$ is parallel to $AB$, because that gives the largest height of the triangle (using $AB$ as base).
Comment: Also, your shoelace formula is wrong, because it's not zero when $C = A$ (at $t = -2$) or when $C = B$ (at $t = 3$).
Answer: The shoelace formula for the points $(4, -4), (9,6), (t^2, 2t)$ gives
$$
A = \frac12\left|4\cdot 6 + 9\cdot 2t + t^2\cdot (-4) - (-4)\cdot 9 - 6\cdot t^2 -
 2t\cdot 4  \right|\\
= \frac12|24 + 18t - 4t^2 + 36 - 6t^2 - 8t|\\
= |30 + 5t - 5t^2|
$$
Since we "[l]et $C$ be a moving point on the parabola between $A$ and $B$", that means that $t$ is between $-2$ (which makes $C = A$) and $3$ (which makes $C = B$). On this interval, $30 + 5t - 5t^2$ is positive, so we can drop the absolute value signs, and find a maximum at $t = 0.5$, which gives $C = (\frac14, 1)$ and area of $31.25$.
Comment: @gilly There are definitely ways of multiplying pairs of coordinates that give the wrong answer, yes.
Comment: Great! I always struggle to decide the order of coordinates in the shoelace formula. How did you decide it?
Comment: @Abcd Does it matter in a triangle
Comment: @Abcd It's a formula I've worked with a lot in the context of cross product of vectors, so I'm used to it, and have a pattern that in my head that I follow. Apart from that, the way I've done it here closely follows the order given on your wikipedia link. If I had followed the wikipedia formula exactly, the last half would've been $- 9\cdot (-4) - t^2 \cdot 6-
 4\cdot 2t$ instead.
Comment: @Arthur This doesn't work: https://imgur.com/a/HydqO . Why?
Comment: @Abcd It does work. You add all the down-right diagonals: $9\cdot2t+t^2\cdot (-4)+4\cdot 6$. Then you subtract all the down-left diagonals: $-6\cdot t^2-2t\cdot 4-(-4)\cdot 9$. What you get is exactly what I have in my first line, just in a slightly different order.
Answer: The equation of $AB$ is $y=2x-12$.
Let $l||AB$.
We see that $S_{\Delta ABC}$ would be maximal for $C\in l$ and $l$ is a tangent line to the parabola.
Let $C\left(\frac{c^2}{4},c\right)$.
Thus, $yc=2\left(x+\frac{c^2}{4}\right)$ is an equation of the tangent line,
which gives $\frac{2}{c}=2$, $c=1$ and $C\left(\frac{1}{4},1\right)$.
Comment: @Abcd I mentioned it in a comment below your question, but the $C$ that gives the largest possible height must necessarily give a tangent that is parallel to $AB$.
Comment: I did not see it. Now I see it.


Real solution of $(\cos x -\sin x)\cdot \bigg(2\tan x+\frac{1}{\cos x}\bigg)+2=0.$

Question:
Real solution of equation $$(\cos x -\sin x)\cdot \bigg(2\tan x+\frac{1}{\cos x}\bigg)+2=0.$$

Try: Using Half angle formula
$\displaystyle \cos x=\frac{1-\tan^2x/2}{1+\tan^2 x/2}$ and $\displaystyle \sin x=\frac{2\tan^2 x/2}{1+\tan^2 x/2}$
Substuting These values in equation
we have an polynomial equation in terms of $t=\tan x/2$
So our equation $$3t^{4}+6t^{3}+8t^{2}-2t-3=0$$
Could Some Help me how to Factorise it.
OR is there is any easiest way How to solve it, Thanks
Comment: $\displaystyle \sin x=\frac{2\tan x/2}{1+\tan^2 x/2}$. Also, $x=\pi$ is a real solution of the equation, but you can't get that from your substitution.
Comment: Are you sure $x=\pi$ is a solution?
Comment: Whoops, my bad.
Answer: That's a nice way to solve but recall that $\sin x=\frac{2t}{1+t^2}$.
I didn't check whether it is only a typo or a mistake in the derivation but note that wolfy suggests $$p(t)=(3t^2-1)(t^2+2t+3)$$.
Answer: HINT:
Since $\sin x=\frac{2t}{1+t^2}$, the equation becomes $$\left(\frac{1-t^2-2t}{1+t^2}\right)\left(\frac{2t+1+t^2}{1-t^2}\right)+2=0\implies -t^4-4t^3-4t^2+1=2t^4-2$$ or $$3t^4+4t^3+4t^2-3=0$$ from which a root is $t=-1$.
Comment: It is very far from a hint in that way and I think the asker can get it by his/herself.


Working out frequency

Question: I have the question "If an object moving in a circle has a period of 24 hours, what is its frequency ?"
I know that frequency $= \frac{1}{T}$,  where $T$ is the period.
Therefore,  $f = \frac{1}{24}*60*60$ ( to get it in seconds)
And so the frequency is $150 Hz$.
Is this correct ?
Comment: Nope.  Think about your answer for a second.  $150 \textrm{ Hz}$ means that it spins $150$ times **every second**.  Does that sound right?
Comment: @Bye_World, take a Look at the answer.
Comment: @THELONEWOLF. You mean your answer?  It looks fine (though I touched up the formatting a bit).
Answer: Time period is $24 \textrm{ hours}$, it means: $$24\cdot 60\cdot 60 \textrm{ seconds}=86400 \textrm{ seconds}$$
Since you already know that:
$$\textrm{frequency} = 1/\textrm{time period}$$
$$\textrm{frequency}=\frac 1{86400}=1.15740740\times 10^{-5}\textrm{ Hz}$$
Always remember to use the data in appropriate units. If you will use the time period in hours, then you are not going to get frequency in Hertz.
Comment: Thank you. Could I also leave the answer as 1.2 x 10^-5 Hz ?
Comment: It depends on how precise or up to what significant figures the answer is required.

Working out frequency


Setting local username when logging in with Azure AD

Question: Is it possible to independently assign what is set as %username% when logging in to a computer that authenticates directly against Azure active directory services?
I'm trying to set things up with a minimal on site presence as this is for a small business (sub 50 users), and throwing an extra 4+ servers into the mix for a "proper" Active Directory Federated Services setup feels like overkill.
Comment: "Setting local username when logging in with Azure AD" What does this mean? Did you mean you want to use Azure AD account logs in to computers?
Comment: I already have that working, we have some software that validates licences against the %username% returned by windows. Right now we have usernames in the format  but when logged in using Azure AD the %username% returned seems to be the AD displayname stripped of spaces. I assume I could set up an on site domain controller, and then connect to azure ad and set up federation, but just using the azure would be preferred if possible.
Answer: not sure exactly what you mean, but there is also variable %userdomain% and command whoami. It both shows AzureAD.


Showing existence of an extension for a measurable function on the whole set $X$

Question: Let $ \mathcal U $ be a $\sigma$-Algebra on a set $X$ and $M \subseteq X$.
Let $f:M\longrightarrow \mathbb R$ be measurable in respect of the Trace-$\sigma$-Algebra $\quad \mathcal U|_M : =\{ U \cap M\mid U\in \mathcal U\}$.
Show: There exists an extension on whole $X$ which is also measurable
I tried to write $X = \bigcup M_i$ for $M_i \subseteq X.$
Since $f$ is measurable  for each $M_i$ then it follows that $f$ is measurable for $\bigcup M_i$ in respect to $\mathcal U|_{\bigcup M_i}.$
Therefore I can define a function $h:X \longrightarrow \mathbb R$  with $h|_M = f$ which is measurable since $f|_{M_i} $ is measurable $\forall M_i$.
I am not really sure if this is the right way so i appreciate any help on this one . Thanks
Comment: No! You're not given that $f$ is measurable "for any $M\subset X$"! If that were so you could just let $M=X$.
Comment: Your suggested outline doesn't make much sense to me - where do the extensions to the $M_i$ come from? Also where you say "it follows that...", it's not so clear to me that it follows.
Comment: Since $f $ is measurable for any $M \subseteq X$ I tried to write $X$ as a union of subsets of $X$. Then i wanted to follow that all functions $f_i : M_i \longrightarrow \mathbb R$ are measurable per definition. All these $f_i$ should define me a new function $h$ with domain $X = \bigcup M_i$ but I guess this is the wrong way on how to deal with that
Comment: I see i completely misread that... thanks
Comment: Is $M\in \mathcal U?$
Answer: First, note you can assume that $f\ge0$, since in general $f=f_1-f_2$ with $f_j\ge0$.
Assume first that $f=\chi_E$, where $E$ is a measurable subset of $M$. Then the definition of "measurable subset of $M$" more or less gives you the extension.
So you're done if $f\ge0$ is simple. Now any positive measurable function is the limit of an increasing sequence of simple functions...
Edit: When I posted that I thought it was more or less a solution. On reflection maybe it's more just a suggestion of a possible approach. The detail I overlooked is this: Say $\phi_n$ is a sequence of simple funtions increasing to $f$. Say $\psi_n$ is a simple function on $X$ extending $\phi_n$. We need at least a little care to ensure that the sequence $\psi_n$ is increasing...
No problem, actually. Extend $\phi_1$ to a simple function $\psi_1$. Now $\phi_{n+1}-\phi_n$ is a non-negative simple function on $M$; the obvious method for extending simple functions extends it to a non-negative simple function $h_1$; let $\psi_2=\psi_1+h_1$. Etc.
Comment: Sorry for bothering so much but I am really confused. I understand your reasoning but I really dont know on how to conclude from this that there is an extension on X
Comment: Well, if you can arrange things so the $\psi_n$ are increasing then they increase to a measurable function on $X$.
Comment: Ahh i understand. Thank you for the help


Automatically setting parent id when creating item from list part in Business Central/AL

Question: I am quite new to building extensions with AL for Business Central. I am trying to setup an extension for a school application. The tables I have built work, and they follow this data model:
School - Course - Lecture
  |     /
Teacher

Inside the Card for School, I am showing a list part for Course.  It correctly shows all courses of a given school. So far so good. But now, whenever I create a Course from this view, I have to remember to set the SchoolId manually, but I would like to do this automatically because we already know which School we are in.
The Course table looks like this:
table 50110 Course
{
    DataClassification = ToBeClassified;
    DrillDownPageId = "Course List";
    LookupPageId = "Course List";

    fields
    {
        field(1; "No."; Code[20])
        ...
        field(5; "SchoolId"; Code[20])
        {
            DataClassification = ToBeClassified;
            TableRelation = School."No.";
        }
    }

    keys
    {
        key(PK; "No.")
        {
            Clustered = true;
        }
    }
}

The Course list part explicitly does not contain the SchoolId, as we would expect this to be managed automatically:
page 50118 "Course List Part"
{
    PageType = ListPart;
    UsageCategory = None;
    SourceTable = Course;
    CardPageId = "Course Card";
    // InsertAllowed = false;

    layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field("No."; "No.") { ApplicationArea = All; }
                field(Name; Name) { ApplicationArea = All; }
                field(CourseOwnerId; CourseOwnerId) { ApplicationArea = All; }
                // field(SchoolId; SchoolId) { ApplicationArea = All; }
            }
        }
    }
}

The School card invokes the Course list part on the appropriate view:
page 50117 "School Card"
{
    PageType = Card;
    UsageCategory = None;
    SourceTable = School;

    layout
    {
        area(Content)
        {
            group(General)
            {
                field("No."; "No.")
                {
                    ApplicationArea = All;

                }
                field(Name; Name)
                {
                    ApplicationArea = All;

                }
            }
            group("Extras 1")
            {
                part("Courses"; "Course List Part")
                {
                    ApplicationArea = All;
                    SubPageLink = SchoolId = field("No.");
                    UpdatePropagation = Both;
                }
            }
        }
    }
}

And of course, the School table, where the No. property is set as the primary key:
table 50113 School
{
    DataClassification = ToBeClassified;
    DrillDownPageId = "School List";
    LookupPageId = "School List";

    fields
    {
        field(1; "No."; Code[20])
        {
            DataClassification = ToBeClassified;
        }
        ...
    }

    keys
    {
        key(PK; "No.")
        {
            Clustered = true;
        }
    }
}

Still, no luck.
Answer: When you add the 'Course' page as to the 'School page', the sub-page link will automatically handle that part of the relationship for you;  when you insert a new record it will automatically populate No. with 'SchoolId'.
e.g. this is how it works on the Sales Order page.
 part(SalesLines; "Sales Order Subform")
            {
                ApplicationArea = Basic, Suite;
                Editable = DynamicEditable;
                Enabled = "Sell-to Customer No." <> '';
                SubPageLink = "Document No." = FIELD("No.");
                UpdatePropagation = Both;
            }

You must also define a table relation from the 'Child' table to the 'Parent' table, e.g.
table 50121 child
{
    fields
    {
        field(1; ParentID; Integer)
        {
            TableRelation = Parent.ID;

The field you're linking on must be a primary key of the Child table, i.e. 'SchoolID' must be in the primary key of 'course' in your code.
Comment: Thanks, I just tried, but unfortunately I did not manage to get your code to working. The SubPageLink alone does not take care of the update, and `No.` is definitely in the primary key of `Course` in my example.

I have neither `Enabled`, nor `Editable`, but I cannot imagine why they would need to be there to implement this behaviour (and I don't know why (still beginner), but `DynamicEditable` does not compile).

Any idea what else I could try?
Comment: Just tried it out myself, and realised we both missed something else, evidently a tablerelation needs to be defined from the child table's field too,  makes sense I guess,  had you done that?  Updated answer.
Comment: Curiouser and curiouser, because indeed I would expect this to work like you describe. I am updating my original question with more code. It looks aligned to what you suggest as far as my inexperienced eyes can see...
Comment: I tried adding the `TableRelation = Parent.Id`, because it was `TableRelation = Parent`, but still: no luck.
Comment: Ahha, I think schoolid must be part of the primary key of the courses table.
Comment: YES! It works!!! Weird and a bit unexpected/obscure, but certainly not absurd.

Interesting to note, is that after adding the SchoolId to the PK of the Course table, the Course list part is still editable, but to add an item I now have to click on Actions -> New, instead of just getting an extra empty line where I can start typing. When Choosing Actions -> New, then I get the SchoolId prefilled.

Any idea what this means, or even where this behaviour would be documented?


Let $f$ be analytic on $\mathbb{D}$, $f(0)=-1$ and $|1+f(z)| < 1+|f(z)|$. Prove $|f'(0)| \leq 4$.

Question: I am trying to solve the following problem:
Let $f$ be analytic on $\mathbb{D} = \{z \in \mathbb{C}: |z|<1\}$, $f(0)=-1$ and $|1+f(z)| < 1+|f(z)|$ for $|z|<1$. Prove $|f'(0)| \leq 4$.
I have an idea of how to do it, but I am stuck at one of the steps.
I'd like to use Schwarz' lemma. So I wish to find a function $h = g \circ f, $ such that $h(0) = 0$, and where $g: f(\mathbb{D}) \rightarrow \mathbb{D}$. Then $h$ would be a function from $\mathbb{D}$ to $\mathbb{D}$, and Schwarz' lemma would apply, so that $|h'(0)| = |g'(f(0))f'(0)| \leq 1.$ If I have then managed to find a $g$ such that $g'(-1) = 1/4$, I believe I would be done with the proof.
Right now, however, I am stuck on what $f(\mathbb{D})$ is. I suppose I should use the assumption that $|1+f(z)| < 1 + |f(z)|$. Simply by drawing a picture I've been able to conclude that if $Im(z) = 0$, then $Re(z)$ cannot be in $\left[0, \infty\right].$ But that's all I have at this point...
Answer: $|1+f(z)| < 1+|f(z)|$ means that equality does not hold in the triangle inequality $$|1+f(z)| \le 1+|f(z)|\, ,$$ and that means that $f(z)$ is not a non-negative real multiple of $1$. In other words:
$$
 f(z) \in \Bbb C \setminus [0, \infty) \, .
$$
It is a bit more convenient to consider
$$
 -f(z) \in \Bbb C \setminus (-\infty, 0] = U \, .
$$
The "main branch" of the square root maps the slit domain $U$ conformally to the right-half plain, and that is mapped conformally to the unit disk with the Möbius transformation $T(w) = \frac{w-1}{w+1}$.
Then
$$
 h(z) = \frac{\sqrt{-f(z)}-1}{\sqrt{-f(z)}+1}
$$
maps $\Bbb D$ into $\Bbb D$ with $h(0) = 0$, and the Schwarz Lemma can be applied: $|h'(0)| \le 1$.
Reversing the compositions we get
$$
 f(z) = - \left( \frac{1+h(z)}{1-h(z)} \right)^2 \\
 f'(z) = - 4 \frac{1+h(z)}{(1-h(z))^3} h'(z) \\
 f'(0) = -4 h'(0)
$$
and the desired conclusion $| f'(0) | \le 4$ follows. Equality holds if and only if
$$
 f(z) = - \left( \frac{1+\lambda z}{1-\lambda z} \right)^2 \\
$$
for some $\lambda \in \Bbb C$ with $|\lambda| = 1$.
Comment: non-negative real multiple
Comment: @mathworker21: Yes, thanks!


Testing statistical significance for hospitalizations by year

Question: My question is whether it is appropriate to use chi-square to determine statistical significance where the independent variable is the number of years of program operation in a medical practice (i.e., Years 1, 2, and 3) and the dependent variable is the number of patients from the practice who have at least one inpatient hospitalization each year. My concern is that because the practice grew each year many, but not all, of the patients in each of the three years are the same. The raw data shows a big decrease in the number of inpatient hospitalizations from the first year to the third year relative to the total number of patients. I'm looking for a way to determine whether the difference is statistically significant and I've put the data into chi-square format (see attached picture).
If chi-square analysis for this data is not appropriate, can you suggest something else? I do not have the individual data, just the group data as displayed in the table. Thanks for your help with this.
Comment: What question are you trying to ask of your data?  It isn't at all evident from their description.
Comment: I am trying to determine whether the reduction in hospitalizations from year 1 to year 3 is statistically significant. The actual numeric reduction from Year 1 to Year 3 (from 43 to 35) is 18%, but the number of patients increased from year 1 to year 3 from 234 to 328, so the percentage of patients hospitalized in year 1 was 18.38, whereas in year 3 the percentage was 10.67, which seems impressive - but we would like to know if the change is statistically significant. Thanks.
Answer: You could use chi square as you propose, or maybe a binomial glm with time as covariate.
For a similar example, see  Testing for significant difference in mortality rate between multiple groups


Managing privacy within a large program

Question: I'm working on a program for robotics with this structure (I'll include what the layers do just for laughs):

Layer A - GUI simple interface to handle buttons, joysticks, etc. Translates these values into commands to send to the control interface.
Layer B - Control evaluates device-read/write-entries from the database and command requests from gui, in order to calculate new device-write-entries for the database
Layer C - Database logical representation of devices, creating a history of values written and read from the devices
Layer D - Hardware talks to physical hardware. Translates device-write-entries into commands and sends them to the devices. Updates the database device-read-entries with values from the devices.

I want to create a java application where no layer is able to call functions which are more than one layer above or below it.
Is it possible to create a project structure using package privacy, or patterns like factories which makes it impossible for code in, lets say Layer A, to import anything from Layers D or C?
Answer: TL;DR there is no one magic bullet solution to this, but many different tools to leverage
There are a variety of different techniques to isolate different parts of a software application, but I don't think there is any one solution that solves everything. Some build systems can restrict dependencies between targets (e.g. Bazel has a visibility property on build targets that can prevent one target from depending on another target, even if they are visible to each other via Java's class visibility) which can be used in conjunction with Java's builtin visibility. For example:
 // Foo.java
 package com.yourcompany.foo;
 public class Foo {}

 // Build rule for Foo.java
 java_library(
    name = "Foo",
    srcs = ["Foo.java"],
    # Restricts visibility to this directory, even though
    # the class visibility was "public"
    visibility = ["//visibility:private"],
 )

 // Bar.java
 package com.yourcompany.bar;

 import com.yourcompany.foo.Bar; // prevented by build visibility system

 public class Bar {
    Foo foo = new Foo();
 }

It is also possible to use interfaces to mediate all interactions between logical components and to hide the implementations of those interfaces (e.g. exposing the implementation only through a service registry interface or through interface dependency injection). For example, with Dagger, you could create a separate component for each layer, which would allow you to write code like:
final class ControllerImpl implements Controller {
   // Since "ControllerImpl" is instantiated / wired into the
   // controller layer, the database dependency is available /
   // exposed for injection within this layer. The access control is
   // strictly performed by the way the dependencies are wired.
   @Inject
   public ControllerImpl(Database database) {
     // ...
   }
}

In addition to the above, you can use dependency analysis / dependency analysis tests or commit hooks to automate detection of dependency rule violations (and trigger errors / reject submissions based on them). For example, a poor man's solution would be to simply scan each file for its package declaration and its import statements, and then have some heuristic to detect a bad dependency.
Another approach is to bundle different components in separate JARs and load them with a custom ClassLoader, which would allow you to prevent illegal accesses using reflection (which could otherwise circumvent any program structure).
In addition to automated methods, manual approaches also have their value. Manual approaches include regular code reviews and policies to be enforced during those code reviews and auditing.
In short, there is no one right answer. It's necessary to use several different approaches in conjunction, depending on how critical this separation is.
Comment: IMO, they would not be advisable for a "small" project.  But if your aim is to build something that has a hope of turning into a viable production ready platform with real security, you have no choice but to come up with a production quality solution.  Don't think people haven't already tried ... and (objectively) failed.  This is a seriously difficult problem.
Comment: Ok. If it's just about neatness and not a strict privacy concern here, then mediating control through interfaces, using an injection framework to manage dependencies, and manual discipline should be more than sufficient, especially if the code base is of a reasonable / manageable size. If you haven't selected a build system yet, though, I would recommend Bazel (I'm a bit biased, though) and, if you are using it, you might as well leverage its visibility restrictions. But if you already have a different build system in mind, then that sort of thing isn't needed.
Comment: Right, this doesn't make sense for something small... for something small, do it in the hackiest way possible that gets you to minimum viable product. But it sounds like this project encompasses several layers of a robotics system, and if you hope for this to get to a production / commercial grade level, then some elements are necessary. (The elements I'm recommending to use in your project are advisable in the medium-large category, and all of them are advisable on the large-ginormous range where some subcomponents handle sensitive data).
Comment: That sounds like a project where strict layering is not strictly necessary.  In fact, strict (strictly enforced) layering sounds tangential to the problem you are really trying to solve.  Put it on one side, and focus of the real problem.
Comment: @StephenC agreed, which is why in my comment, I've indicated that only some pieces are needed to be "neat" and the other pieces (like custom class loaders, automated dependency analysis, etc.) for stricter enforcement are not necessary.
Comment: Wow, I didn't realize how big a question this would actually be! The idea of restricting layer access was to make sure code was maintainable. Would any of these solutions be advisable for a extracurricular project, which will probably only last a year or two tops? Or would as Stephen C said, "Rely on programmer discipline" be a more appropriate approach?
Comment: @StephenC and Michael Aaron Safyan, Thank you very much for the advice! I'll have to take some time this week and look deeper into these concepts :)
Answer: This is not something that you can achieve using access modifiers alone.
You also can't do it by (somehow) controlling import ... because the Java language doesn't place any (extra) restrictions on imports.  (The import directive is really just syntactic sugar so that you don't need to use fully-qualified names everywhere.)
So what else could you do?

You could try to implement runtime restrictions to prevent the wrong layer getting access to factory objects.  But such restrictions are easily subverted, deliberately or by accident.
You could use some kind of internal "capability" or "credential" mechanism, but it is hard to see how you would prevent credential leakage. (If the credentials were managed by a security manager (see below) that might work, but that's making the problem more complicated.)

The only way I think you could do it would be to implement a custom SecurityManager, and implement security checks each time there is a potentially layer-crossing call.  For example, it is possible (though expensive) for a security manager to check the call stack to find what method / class / package called it.  You would also need to turn off certain reflective operations that can be used to (trivially) subvert the security manager.  Essentially, all but the inner ring needs to be treated as "untrusted" code.
Frankly, implementing this kind of thing with a JVM with "hacker-proof" security is probably beyond the capability of a mortal human.  (Sun / Oracle haven't succeeded yet ....)

The other alternatives are:

Rely on programmer discipline.
Rely on static analysis of the codebase; e.g. aided by annotations that document the access rules.  You would need to write your own code analyser to do this.
Use address-space separation, and small footprint, security-minded APIs between the layers.  (We are no longer talking about a single conventional JVM here ...)
Comment: Just asked the same question to Michael Aaron Safyan, but in your opinion are these expensive/ involved approaches realistic for the sake code maintenance? or is programmer discipline the way to go?
Comment: Programmer discipline is sufficient if you are only concerned about code maintainability.  IMO.

Managing privacy within a large program


How to add my own python code in django in views.py index function

Question: I have a code of python in different files: st.py and mydefinations.py, yahoo.py. And These codes are working fine but whenever I integrate this code in Django. It shows my error. This is my code of views.py in Django.
def index(request):
    latest_stocks_list = Stock.objects.all()
    template = loader.get_template('stocks/index.html')
    context = {
        'latest_stocks_list': latest_stocks_list,
    }
    return HttpResponse(template.render(context, request))

And I want to add the following code in the index function
from my definitions import *
from yahoo import *

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0'}
tickerslist = ["AAPL"]
prntvar = {'prntnum': 0}
mydef = mydefinations()
for ticker in tickerslist:
    try:
        testdic = {'Var1': 0, 'Var2': 0}
        Ticker_stats = {}
        Ticker_summary = {}
        yahoo = my_yahoo(headers, ticker)
        Ticker_stats = yahoo.yahoo_stats()
        print(Ticker_stats)
    except Exception as e:
        pass

When I add code in the index and import line in the start and error shows that

my definitions module is not found

What should I do?
Answer: Try updating the imports like this,
from your_app_name.mydefinations import *

Comment: Yes, but django will look for your package in the root directory while executing it. have you tried it?
Comment: But this mydefinations file is as it is in the same folder
Comment: To give you some more information, even though we have models.py in the same package, we will import that as 'from app_name import models' in the views.py right?
Comment: This works fine but now BeautifulSoap module is not found. Now what should I do? This BeautifulSoap library is in mydefinations
Comment: Please post your directory structure here.


jquery form submit and textarea refresh

Question: I need help with jQuery and ajax. need to load textarea content from file after submit.
can't figure out this. here's the code:

  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />

  <meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />

  <title></title>

  <textarea readonly="readonly" cols="150" id="output">
<?php
    echo $api->consoleOutput(50, 0); ?>
</textarea>

  <form action="" name="execute" method="post" id="console">
    <input type="text" id="command" name="command" /> <input type="submit" id="submit"
    value="siÅ³sti" /> <button id="button">siusti</button>
  </form><?php
      $api->sendCommand($_POST['command'])
      ?>

all the other methods I have tried, the doesn't seem to help...
Stackoverflow rules for fast answers ;)
Comment: You need to include the plugin as well, usually it's named `jquery.validate.js`
Comment: Cheers, edited my answer as well then.
Answer: Your form ID is "console", not "execute" so change this line:
$("#execute").validate({

To this:
$("#console").validate({

You can also select the form by its name, but can't see any advantage in this.
Edit: in order for all of this to work, you also have to reference the plugin itself, usually named jquery.validate.js.
Comment: @Justas If you add `alert(data);` inside the `$.post()` method, what do you see?
Comment: so could so tell me, how to make textarea refresh after submit?
Comment: @Justas see my comment on your question, looks like you don't have reference to the plugin thus `.validate()` can't really work.

jquery form submit and textarea refresh


Inner dependence of Independent random vectors

Question: If $X = (X_1,X_2)$ and $Y = (Y_1,Y_2)$ , $X$ and $Y$ are stochastically independent can $X_1$ and $Y_1$ be dependent?
Comment: No.${}{}{}{}{}{}$
Answer: Hint:
$$
P(X_1\in A,Y_1\in B)=P(X\in A\times\mathbb{R},Y\in B\times\mathbb{R}).
$$
Answer: Let us consider that all variables are continuous and let us consider probability density functions $f$ that are distinguished by their arguments.
The independence of $X$ and $Y$ means
$$f(X,Y)=f(X)(Y)$$
The right hand side can be written using the chain rule as
$$f(X)f(Y) = f(X_2,X_1)f(Y_2,Y_1)=f(X_2|X_1)f(X_1)f(Y_2|Y_1)f(Y_1)=f(X_2|X_1)f(Y_2|Y_1)f(X_1)f(Y_1)=f(X_2,Y_2|X_1,Y_1)f(X_1)f(Y_1)$$
where the last equality stems from the fact that $X_2$ and $Y_2$ do not occur in $f(X_1)f(Y_1)$ and $f(X_1)f(Y_1)$ define a probability density on $X_2,X_1$.
The left hand side can be also decomposed by the chain rule
$$f(X,Y)=f(X_2,Y_2|X_1,Y_1)f(X_1,Y_1)$$
From the equality of left and right sides we can see the independence of $X_1$ and $X_2$.
Comment: Of course the result has nothing to do with the random variables being continuous and, when they are, the notations $f(X)$, $f(Y)$, $f(X_2,X_1)$, $f(Y_2,Y_1)$, $f(X_2|X_1)$, etc., are all quite objectionable.


How do you uniformly sample spans from a bounded line?

Question: Suppose you have a bounded and continuous line. For example, the line could include all real numbers between 0 and 3. How do you sample spans from the line such that...

Any point on the line has an equal chance of being included in the span.
The distribution of span lengths is uniform.

My attempted solution:
import random

max_length = 15.0
bounds = (0.0, 3.0)

length = random.uniform(0, max_length)
start = random.uniform(bounds[0] - length, bounds[1])
end = min(start + length, bounds[1])
start = max(start, bounds[0])

This solution is able to fulfill the first criterion and not the second criterion.
EDIT: Following the lead of BruceET, I have plotted the distribution of span lengths:
import random
from matplotlib import pyplot
import seaborn

max_length = 6
bounds = (0, 3)
num_samples = 10**6

samples = []
for _ in range(num_samples):
    length = random.uniform(0, max_length)
    start = random.uniform(bounds[0] - length, bounds[1])
    end = min(start + length, bounds[1])
    start = max(start, bounds[0])
    samples.append(end - start)

seaborn.distplot(
    samples,
    hist=True,
    kde=True,
    bins=30,
    color='darkblue',
    hist_kws={'edgecolor': 'black'},
    kde_kws={'linewidth': 1})
pyplot.show()

Comment: There are exactly two ways of doing this: (1) make the "spans" all have zero length (and distribute their endpoints uniformly); (2) make them all have length 3.  If by "uniform" you allow *discrete* uniform distributions, there are other solutions.  For instance, draw the intervals $[0,3/2)$ and $[3/2, 3)$ with equal probabilities of $1/4$ and draw the intervals $[0,3/4),$ $[3/4,3/2),$ $[3/2,9/4),$ and $[9/4,3)$ with equal probabilities of $1/8.$ The distribution of span lengths is uniform on the set $\{3/4,3/2\}.$ Is this the sort of thing you are looking for?
Comment: Thank you for your creative approach! You are right and that would work. It wouldn't be ideal for me. I should clarify that I'd also like to maximize the variety. For context, this solution will be used to train a machine learning model and diversity is important.
Comment: Generalize, then. For instance, let $n\ge 2$ be a positive integer.  Consider the sequence $$(a) = (a_1,a_2,\ldots,a_n)=\frac{1}{n!},\frac{2}{n!},\ldots,\frac{n}{n!}.$$ Each of the $a_i$ is the reciprocal of the *integer* $n!/i.$ Thus, you may sample $i$ *uniformly* from the set $\{1,2,\ldots,n\}$ and then, conditional on $i,$ sample a span $[(k-1)a_i, ka_i)$ *uniformly* from $k\in\{1,2,\ldots, n!/n\}.$
Answer: Comment: You're having trouble with your second simulation because the 'span' of several uniform random variables is is not uniform.
In R, the function range gives the endpoints, taking the difference gives
what you call the 'span'.
Here is a simulation in R of the span lengths from 100,000 samples of size $n=5$ from $\mathsf{Unif}(0, 3).$
set.seed(2020)
span.5 = replicate(10^6, diff(range(runif(5,0,3))))
summary(span.5)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
0.07294 1.63716 2.05782 1.99968 2.41826 2.99932
hist(span.5, prob=T, col="skyblue2")
curve((1/3)*dbeta(x/3, 4, 2), add=T, col="red", lwd=2)

Comment: @MichaelPetrochuk if you enforce the lengths to be uniform by IRT or such, the sampling probability along the line will no longer be uniform. Your criteria are more fundamentally incompatible: any points near the center of the line are "easier" to sample because of overlaps (e.g. think of all possible placements for segments of length $2$), so unless you prevent overlaps or enforce some kind of correlation between segment position and length, which you probably don't want, I don't see how this is possible. Sampling along a circle, on the other hand, would be easy, if that helps...
Comment: Yes. Your right. Since the above problem allows me to choose the `length`, I have been thinking about picking a `length` to correct for that.
Comment: In case it helps, I just now included the density function of the theoretical 4-parameter beta distribution.
Comment: Thanks for your comment and that's helpful. I updated the question with the current distribution that I am seeing.
Comment: Do you know the name of the distribution that I posted above? I think if I can find the inverse of that distribution then I can correct for it.
Comment: Not sure what correction you have in mind. But name of dist'n hinted in the R code that draws the red density line. It is a 4-parameter beta distribution with support $(0, 3)$ and shape parameters 4 and 2. Maybe see Wikipedia on 'beta distribution'.


Is there a specific term to denote playing a wide chord on a piano?

Question: I'm a beginner who can play chords on a piano.
If I play a C chord on the keyboard I would play C-E-G, or one of the two inversions (I.E. G-C-E or E-G-C).
I've noticed some people play chords "disconnected". That is, they'd play a C and a G but the E would be to the right of the G key.
I've never thought about trying that before. I wondered, is there a specific name for this type of chord? Why do people do it?
Answer: In general, chords with the notes closer together are called closed voicings, while chords with the notes farther apart are called open voicings. For simple triad chords like the ones you mentioned, a chord is closed if it occurs within a single octave and the chord is open if it is spread out across more than one octave. More generally though, a chord is closed if it's the most compact voicing of the chord.
There is another technique worth mentioning: the example you've described is called a "drop 2" voicing or drop 2 chord. This is when you take the second highest note from a closed voicing and move it down an octave. The other notes remain unchanged. In your example, you started with a 2nd inversion C Maj triad (G3-C4-E4). Then we take the second highest note (C4) and move it down an octave (to C3). This gives the final drop 2 voicing of C3-G3-E4.
Here's a more elaborate example. The bottom shows the exact same voicings, but with the second highest note dropped down an octave for each chord.

If you are working with 4-note chords, you still take the second highest note and drop it down an octave. For example, here are some repeating Dmin6 A7♭9 chords. The bottom shows the same chord voicings, but with the second highest note dropped down an octave.
This is done to achieve a more open/spread out sound. Being able to play both increases one's musical vocabulary. That's generally helpful, because variety is a lot of what makes music sound good. Playing just closed voicings for an entire song can become boring for a listener. Using drop 2 voicings adds variety.
Comment: @Aaron, I'm not sure that "closed" is incorrect terminology. See, for example, [1](https://college.berklee.edu/people/suzanne-davis), [2](http://jazzpianovoicings.com/2016/02/25/the-drop-2-piano-chord-voicing/), [3](https://jazzpianolessons.online/start-here/lesson-6-open-closed-voicing/), [4](https://www.thejazzresource.com/4_note_voicings.html), [5](https://jazztutorial.com/articles/what-is-a-jazz-piano-chord-voicing)
Comment: "Close:" is the correct term, though there are many, many references to "closed". Bizarrely, I've been posting the wrong link in making these corrections. See [When the tones in a chord are packed together, is it in "Close position" or "Closed position"?](https://music.stackexchange.com/a/105498/70803). I believe the text books and music dictionaries cited can be taken as definitive.
Comment: @Aaron, I don't contest that "close" is also correct. Both are used in the same source types, have well-understood meaning, & are correct. FWIW, I don't think online dictionaries are definitive when it comes to musical terms. Textbooks, educational, & academic sources are better. But there's nowhere near consensus. See [this book](https://www.shermusic.com/9780997661750.php), [this book](https://www.amazon.com/Essential-Voicings-Jazz-Piano-Vol-1/dp/B099BYQS8G), [this paper](https://quod.lib.umich.edu/cgi/p/pod/dod-idx/fluid-chord-voicing-generator.pdf?c=icmc;idno=bbp2372.2016.033;format=pdf),
Comment: and [this dissertation](http://ufdcimages.uflib.ufl.edu/UF/00/09/94/72/00001/teachingbasicjaz00lars.pdf), as more examples. One of the original sources I cited is a piano professor at Berklee College of Music--it doesn't get much more authoritative than that. But I think both terms are correct, and I'm puzzled by the suggestion that either is incorrect. Why can't both be acceptable terms?
Answer: if the notes are close together it is a Close Voicing. If they are spread apart as in your question it is said to be Open Voicing.
More info can be found here.
The note that is lowest determines the Inversion.
A root note (c in your example) that is lowest is said to be in Root Position.
E (the 3rd) in the bass is 1st inversion.
G (the 5th) is 2nd inversion.
if you have a 7th chord with the 7th in the bass it is 3rd inversion.
Answer: Open voicing. For close voicing, the notes (3 in the normal chord called a triad) are as close as possible to each other, as you have been playing until now. Open voicing happens when one at least is moved an octave or more from its close position.
There is also no need to play only the three notes from the basic triad. It's common to double up on one two or all of the notes. You could actually play two close triads, one with each hand, one, say, in root and the other in second inversion. Or - a low 1, a middle 3 and a higher 5, still constituting an (open voiced) chord.
An oft used open voiced triad in l.h. is C- G - E, arpeggiated and pedalled.
Answer: I agree with all the comments. I just want to add that, on piano, open voicing will usually need to be split between the two hands. It doesn't have to be the same number of notes in each hand, but one hand will not normally be able to cover all the notes. The reason why close voicing is used so much on piano is because it makes it easy to move from chord to chord while playing a bass line in the left hand. Playing open voicing would be much easier in a group with a bass player.


I can't find the mistake in my for loop code in r

Question: I have this code:
test_x <- 2000

#functions used:

`%+<-%` = function(e1,e2) eval.parent(substitute(e1 <- e1 + e2))

CreateData <- function()
{
numeric(test_x)
}

#variables

test_sum <- 0
test_q <- 0
test_q <- CreateData()
test_Q <- 0
test_Q <- CreateData()
test_step <- 0.01

#two for loops

for (i in test_x) {
  test_q[i] <- 40
}
for (i in (test_x - 1):0) {
  test_sum %+<-% (test_q[i]*test_step)
  test_Q[i] <- test_sum
}

I'm expecting that the first for loop would fill test_q with 40 in each of the 2000 locations, but instead each spot is zero.
The second loop thus also stays zero.
No errors. What did I do wrong?
Comment: you are doing `for (i in test_x)`, but `x_test = 2000` so you're only doing `for (i in 2000)` so `i` will only take the value `2000`, you have to do `for (i in 1:test_x)`
Comment: You're totally right. Not sure how I didn't see that. If you post that as a solution I'll mark it as solved.
Answer: In the first loop i is only taking the value 2000, then you should modify the first loop as follows :
for (i in 1:test_x) {
  test_q[i] <- 40
}


Como separa o valor de elementos de uma coluna por delimitador ("|" e " ") no pandas?

Question: vamos imaginar que temos uma coluna com essas informações:
|Nomes|    Nome_meio     |    Sobrenome |
|Larissa|    Manoela    |Santos|
|Manoel|    Rosa    |Toy|
|Ronaldo|    Fenomeno    |Pereira|
|Elon|    Musk    |da Silva|

Preciso fazer um Split que retire o delimitador ("|" e " ")
meu código:

import pandas as pd

df = pd.read_excel('teste1.xlsx')

df[['Nome', 'Nome_meio', 'Sobrenome']] = df['|Nomes| Nome_meio|  Sobrenome|'].str.split('|' ,n=2,expand=True)

df1 = df.drop(columns=['|Nomes| Nome_meio|  Sobrenome|'],axis=1)

df1.to_excel('teste1.xlsx' ,index=False)

Output do meu código:
Coluna1   Coluna2    Coluna3
Nome      Nome_meio  Sobrenome
          Larissa       Manola    |Santos|
          Manoel        Rosa    |Toy|
          Ronaldo       Fenomeno    |Pereira|
          Elon          Musk    |da Silva|

Output esperado:
Coluna1     Coluna2     Coluna3
Nomes       Nome_meio   Sobrenome
Larissa     Manoela     Santos
Manoel      Rosa        Toy
Ronaldo     Fenomeno    Pereira
Elon        Musk        da Silva

Comment: não esqueça de confirmar a resposta abaixo, se ela responde a sua pergunta.
Answer: Solução baseada no exemplo que você apresentou.
Criando base de teste
import pandas as pd

df = pd.DataFrame({"coluna": ["|Nomes|    Nome_meio     |    Sobrenome |","|Larissa|    Manoela    |Santos|","|Manoel|    Rosa    |Toy|","|Ronaldo|    Fenomeno    |Pereira|","|Elon|    Musk    |da Silva|"]})

df
                                      coluna
0  |Nomes|    Nome_meio     |    Sobrenome |
1           |Larissa|    Manoela    |Santos|
2                  |Manoel|    Rosa    |Toy|
3         |Ronaldo|    Fenomeno    |Pereira|
4               |Elon|    Musk    |da Silva|

Removendo primeiro e último delimitador
df["coluna"] = df["coluna"].str[1:-1]

df
                                    coluna
0  Nomes|    Nome_meio     |    Sobrenome
1           Larissa|    Manoela    |Santos
2                  Manoel|    Rosa    |Toy
3         Ronaldo|    Fenomeno    |Pereira
4               Elon|    Musk    |da Silva

Transformando string com delimitador (|) para lista
df["coluna"] = df["coluna"].str.split("|")

df
                                        coluna
0  [Nomes,     Nome_meio     ,     Sobrenome ]
1           [Larissa,     Manoela    , Santos]
2                  [Manoel,     Rosa    , Toy]
3         [Ronaldo,     Fenomeno    , Pereira]
4               [Elon,     Musk    , da Silva]

Criando novo dataframe contendo apenas as colunas
novo_df = pd.DataFrame(df['coluna'].to_list(), columns = ['Nome', 'Nome_meio', 'Sobrenome'])

novo_df

      Nome           Nome_meio       Sobrenome
0    Nomes      Nome_meio           Sobrenome
1  Larissa         Manoela              Santos
2   Manoel            Rosa                 Toy
3  Ronaldo        Fenomeno             Pereira
4     Elon            Musk            da Silva

Concatenando dataframes lado a lado
df = pd.concat([df, novo_df], axis=1)

df
                                        coluna     Nome           Nome_meio       Sobrenome
0  [Nomes,     Nome_meio     ,     Sobrenome ]    Nomes      Nome_meio           Sobrenome
1           [Larissa,     Manoela    , Santos]  Larissa         Manoela              Santos
2                  [Manoel,     Rosa    , Toy]   Manoel            Rosa                 Toy
3         [Ronaldo,     Fenomeno    , Pereira]  Ronaldo        Fenomeno             Pereira
4               [Elon,     Musk    , da Silva]     Elon            Musk            da Silva

Limpando espaços à esquerda
df["Nome"] = df["Nome"].str.strip()
df["Nome_meio"] = df["Nome_meio"].str.strip()
df["Sobrenome"] = df["Sobrenome"].str.strip()

df
                                        coluna     Nome  Nome_meio  Sobrenome
0  [Nomes,     Nome_meio     ,     Sobrenome ]    Nomes  Nome_meio  Sobrenome
1           [Larissa,     Manoela    , Santos]  Larissa    Manoela     Santos
2                  [Manoel,     Rosa    , Toy]   Manoel       Rosa        Toy
3         [Ronaldo,     Fenomeno    , Pereira]  Ronaldo   Fenomeno    Pereira
4               [Elon,     Musk    , da Silva]     Elon       Musk   da Silva

Apagando primeira linha
df = df.drop(df.index[0])

df

                                 coluna     Nome Nome_meio Sobrenome
1    [Larissa,     Manoela    , Santos]  Larissa   Manoela    Santos
2           [Manoel,     Rosa    , Toy]   Manoel      Rosa       Toy
3  [Ronaldo,     Fenomeno    , Pereira]  Ronaldo  Fenomeno   Pereira
4        [Elon,     Musk    , da Silva]     Elon      Musk  da Silva

Nota: É possível economizar passos chaining os comandos como por exemplo abaixo:
novo_df = pd.DataFrame(df['coluna'].str[1:-1].str.split("|").to_list(), columns = ['Nome', 'Nome_meio', 'Sobrenome'])

Comment: Vou usar os seu dados para apresentar uma resposta.
Comment: Maravilha, corrigiu os problemas com o delimitador. Ótima solução!
Answer: Se nos nortearmos no conjunto hipotético de dados propostos na pergunta e consolidados nessa resposta
import pandas as pd

df1 = pd.DataFrame(
 {"coluna": ["|Nomes|    Nome_meio     |    Sobrenome |",
             "|Larissa|    Manoela    |Santos|",
             "|Manoel|    Rosa    |Toy|",
             "|Ronaldo|    Fenomeno    |Pereira|",
             "|Elon|    Musk    |da Silva|"
            ]
 }
)

Uma solução é gerar um novo DataFrame a partir dos dados da coluna em questão usando o método pandas.read_csv(). Seguindo os passos:

Remova o primeiro e o último caractere | de cada linha da coluna usando o método str.strip() que retorna uma cópia da string com caracteres no início e no final removidos segundo o argumento passado ao método.

Com o método pandas.Series.str.cat() junte todas as linhas da coluna em uma string, configurando o separador de linhas para sep="\n".

A partir da string gerada anteriormente crie na memória um fluxo de texto com io.StringIO().

Com o método pandas.read_csv() leia o fluxo de texto mudando o delimitador do padrão , para | a ser usado configurando parâmetro sep="|"

import io
import pandas as pd

df1 = pd.DataFrame({"coluna": ["|Nomes|    Nome_meio     |    Sobrenome |","|Larissa|    Manoela    |Santos|","|Manoel|    Rosa    |Toy|","|Ronaldo|    Fenomeno    |Pereira|","|Elon|    Musk    |da Silva|"]})

csv = df1["coluna"].str.strip("|").str.cat(sep="\n")
df2 = pd.read_csv(io.StringIO(csv), sep="|")

print(df2.head())
#    Nomes     Nome_meio          Sobrenome
#0  Larissa        Manoela             Santos
#1   Manoel           Rosa                Toy
#2  Ronaldo       Fenomeno            Pereira
#3     Elon           Musk           da Silva

Para remover os espaço dos dados das colunas ao ler um csv é possível utilizar o parâmetro converters de pandas.read_csv() que é um dicionário de funções para trabalhar valores em determinadas colunas. As chaves podem ser números inteiros ou rótulos de colunas. Especificamente usei converters={1:str.strip} pois no exemplo apenas a coluna Nome_meio apresenta os espaços, porém nada impede de aplicar uma mesma função a todoas ou mais de uma coluna converters={0: str.strip ,1:str.strip 2: str.strip}
Os rótulos das colunas também contém espaços que podem serem removidos com str.strip() assim df2.columns = df2.columns.str.strip()
Exemplo completo:
import io
import pandas as pd

df1 = pd.DataFrame({"coluna": ["|Nomes|    Nome_meio     |    Sobrenome |","|Larissa|    Manoela    |Santos|","|Manoel|    Rosa    |Toy|","|Ronaldo|    Fenomeno    |Pereira|","|Elon|    Musk    |da Silva|"]})

csv = df1["coluna"].str.strip("|").str.cat(sep="\n")
df2 = pd.read_csv(io.StringIO(csv), sep="|", converters={1:str.strip})

df2.columns = df2.columns.str.strip()

print(df2.head())

#     Nomes Nome_meio Sobrenome
#0  Larissa   Manoela    Santos
#1   Manoel      Rosa       Toy
#2  Ronaldo  Fenomeno   Pereira
#3     Elon      Musk  da Silva

Teste o exemplo no Replit
Comment: boa solução usando o `str.cat()`. Porém, (i) não removeu os espaços, (ii) caso o `df` original possua mais colunas seria necessário fazer o concat (ou merge) de qualquer forma.
Comment: Exatamente como nosso amigo Paulo Marques mecionou foi uma boa solução. Pois removeu o delimitador "|" , porém não removeu os espaços. Podemos usar `replace()` para remover os espaços.
Comment: @ANDERSONHENRIQUELUIZ Fiz uma edição vejam se adequa suas necessidades.


Obter o drawable usado como imagem do CheckBox

Question: Sempre que eu tenho guardar a imagem associada a uma checkbox através do método imagem = minha_checkbox.getButtonDrawable(); dá me sempre um erro chamado call requires API level 23 (current min is 17)
Como é que eu posso resolver isto?
Answer: O método getButtonDrawable() só foi introduzido na classe CheckBox(CompoundButton) na versão 23 da API.
Tem duas soluções:

Altera a versão mínima da aplicação para 23(android:minSdkVersion="23").
Recorre à classe CompoundButtonCompat e utiliza o seu método estático getButtonDrawable():
imagem = CompoundButtonCompat.getButtonDrawable(minha_checkbox);

Nota: Necessita da Android Support Library, revision 23.0.1 ou superior.


theme_preprocess_views_view_fields() function in drupal7 does not accept static variable as index

Question: This is my code
function THEME_preprocess_views_view_fields(&$variables)
{
    static $i = 0;
    $variables['address'] = t($variables['view']->result[$i]->field_address[0]['raw']['uri']);
    $variables['address1'] = t($variables['view']->result[0]->field_address[0]['raw']['uri']);
    $i++;
}

I wrote the following code in views-view-fields-VIEWNAME--page.tpl.php :
<?php print $address; ?>
<?php print $address1; ?>

the second print successfully printed its relevant value but the first one displayed nothing.
I tried to use this trick but i failed :
<?php
if($i==0)
    $variables['address'] = t($variables['view']->result[0]->field_address[0]['raw']['uri'];
if($i==1)
    $variables['address'] = t($variables['view']->result[1]->field_address[0]['raw']['uri'];
.
.
.

?>

why can't I use static variable as index?

UPDATE
after useful comment of Clive and arpitr I modified my code and I created two THEME_preprocess_views_view_fields functions separately as follow:
function THEME_preprocess_views_view_fields(&$variables)
{
    static $i = 0;
    $view = $variables['view'];
    if($view->name == "MY_VIEW_NAME")
    {
    $variables['address'] = t($variables['view']->result[$i]->field_address[0]['raw']['uri']);
    $i++;
     }
}

and this one
function THEME_preprocess_views_view_fields(&$variables)
{
    static $i = 0;
    $view = $variables['view'];
    if($view->name == "MY_VIEW_NAME")
    {
    $variables['address'] = t($variables['view']->result[$i]->field_address[0]['raw']['uri']);
     }
}

for the upper one it was the result
Array

and the second one (without $i++) successfully printed the right value.
Comment: do a dpm($i) inside THEME_preprocess_views_view_fields() and check the value it shows, I doubt the variable count is exceeding the value you are expecting result for.
Comment: @arpitr Thanks for your suggestion. I did this, there are three elements but the result was 0 1 2 ... 15 16. so I modified the code and I updated my post. you can see it. thanks again
Comment: got you :), you should rather add this as answer.
Comment: @arpitr it is very helpful but problem did not solve yet and I must complete this project as soon as possible :(
Comment: The static variables work fine for me. I just want to make sure you are using the correct spelling of properties here: usually, the field name in the `$result` array is referenced as `field_`, which, in your case would be `field_field_address` an NOT `field_address`.
Comment: @pamatt then why when I use 0 or 1 as index it works?
Comment: If you are still stuck at that send more info, such as what kind of field exactly is field_address (I assume it would be a contrib module's field, but which?), and what is the content of the array you printed. An outline of what arre you trying to do exactly would be a premium. And please be aware that the answer provided by @clive is a solid one to your original question...
Answer: Static vars aren't special beyond persisting inside the scope of the function they were created, for the duration of a single page build. You categorically can use a static var as an array index.
Take the following code:
function some_test(&$variables) {
  static $i = 0;
  print $variables[$i];
  $i++;
}

$variables = array(
  0 => 'test1',
  1 => 'test2',
);

some_test($variables);
some_test($variables);

Which outputs the following:
test1
test2

Proving that $variables[$i] is accessed as expected.
The problem with you code must be somewhere else, as it's not being caused by a language issue as you suggest.
At a wild guess, $variables['view']->result isn't keyed in the same way you expect it to be (possibly keyed by the result's base table ID instead of a zero-based list). Dumping out $variables['view']->result should tell you pretty quickly what's happening.
Comment: I already dumped `$variables['view']->result`. I updated my post and showed the results and sounds like the problem is not by being `static`
Comment: I'm not sure what else I can tell you I'm afraid - your problem 100%, definitely isn't being caused by the use of a `static` var. It's completely illogical, unless you have a patched version of the PHP language which treats `static` vars differently (highly unlikely that you'd have that without knowing about it). The snippet in the answer above proves the point nice and succinctly - the problem you're having is caused by something else. If I had to guess, I would assume that `$variables['view']->result[1]` doesn't exist


Delete empty rows in comment in Excel using VBA

Question: I'm looking for a way to delete empty rows in comments using VBA. I have an Excel file with loads of corrupted comments, containing empty rows, and going through them one by one is not an option.
I haven't identified a command for editing rows in comments, and don't know where to start, so I don't have any code to show you guys. But I'm thinking in the line of:
For Each comment In ActiveSheet.Comments
    "REMOVE EMPTY ROWS" <-- What to put here?
Next comment

Hope that you can help me anyway!
EDIT:
All my empty lines are at the end of the comment like this:
Comment: There are lots of readymade code available for this on google. Did you try to google ?
Comment: Of course I tried Google! But I didn't find anything,
Answer: I found the answer. It seems that it's not empty rows, it's just the size of the comment that was changed somehow. So this code fixed it:
Sub Comments_AutoSize()

Dim MyComments As Comment
Dim lArea As Long
For Each MyComments In ActiveSheet.Comments
  With MyComments
    .Shape.TextFrame.AutoSize = True
    If .Shape.Width > 300 Then
      lArea = .Shape.Width * .Shape.Height
      .Shape.Width = 200
      .Shape.Height = (lArea / 200) * 1.1
    End If
  End With
Next
End Sub

Answer: Suppose your comment looks like this

You could try this
Sub RemoveEmptyLinesInComments()

    Dim c As Comment
    For Each c In ActiveSheet.Comments
        c.Text Text:=Replace(c.Text, vbLf, Chr(32))
    Next c

End Sub

to achieve

Update
Ok, after you've edited your question and changed the meaning with the provided details Ive come up with another code as a solution. Try
Sub RemoveEmptiesFromComments()

    Dim c As Comment
    For Each c In ActiveSheet.Comments
        Dim v As Variant
        v = Split(c.Text, Chr(32))
        Dim i As Long, s As String
        For i = LBound(v) To UBound(v) - 1
            s = s & Chr(32) & v(i)
        Next i
        Dim rng As Range
        Set rng = c.Parent
        c.Delete
        rng.AddComment Text:=s
        rng.Comment.Shape.TextFrame.AutoSize = True
    Next c

End Sub

Comment: Hmm, didn't get that to work. All my empty lines are at the end of the comment, see my edited question above, does that matter?


Postfix: mail delivered locally, but I wanted relayhost delivery

Question: I work at example.net :-) and my team's server is named tardis.example.net .  Any mail sent to us must first go through our company's internal relay hosts.  Although the messages are delivered to our server correctly, the recipient address is rewritten from:
email@example.com

to:
firstname.lastname@example.com

As a result, our default Postfix (2.6.6) configuration refuses to deliver the message:
Nov 27 15:49:23 tardis postfix/qmgr[10564]: B6CC73FA22:
from=<email@example.com>, size=3953, nrcpt=1 (queue active)

Nov 27 15:49:24 tardis postfix/smtp[10580]: B6CC73FA22: to=<email@example.com>,
orig_to=<firstname.lastname@example.com>,
relay=outbound.example.net[172.30.113.194]:25,
delay=0.71, delays=0.47/0.01/0.14/0.1, dsn=5.1.1, status=bounced
(host outbound.example.net[172.30.113.194] said:
550 5.1.1 <firstname.lastname@example.com>...  User unknown (in reply to RCPT TO command))

My solution to this was to change main.cf from this:
myhostname    = tardis.example.net
mydomain      = example.net
mydestination = $myhostname, localhost.$mydomain, localhost

to this:
myhostname    = tardis.example.net
mydomain      = example.net
mydestination = $myhostname, $mydomain, localhost.$mydomain, localhost

This works fine; by accepting mail for $mydomain, tardis.example.net now accepts incoming mail even with the recipient changed to firstname.lastname@example.com
The problem, however, is that all outgoing mail from our server to @example.net is now treated as local mail.  Instead of being forwarded to $relayhost (outbound.example.net), Postfix attempts to deliver it to a local user on tardis.example.net .
How can I configure our server to accept incoming @example.net mail, but send ALL outgoing messages to $relayhost (with the possible exception of outgoing mail destined for @tardis.example.net, which is the only thing that should be delivered locally) ?
I looked through the FAQ on mail relaying and the various relay-related options in the documentation but could not find anything that would help me.
If you need further configuration info, I'll be happy to provide it. Thanks to anyone who can help.
Comment: It would have been better, I think, to fix the upstream mail server that was causing the original problem.
Comment: In this case example.net is a very big company.  The upstream mail administrators probably had some good reason to rewrite all addresses with a canonical @example.net, and won't particularly be interested in what our team would prefer.  :-/
Comment: To me it looks like your postfix is changing the recipient and then tries to send that email back out, and their mail server says firstname.lastname@example.com does not exist. Or am I missing something?
Answer: Gah! Yes, you're right, Ismooth - I hadn't realized the difference between the to and orig_to line was coming from Postfix, not the upstream mail host.  In this case, the standard distribution of Postfix loaded onto our server by the company contained the line:
masquerade_domains = example.net

which of course stripped off the "tardis" bit and turned email@example.com into email@example.com.
The solution was to remove that line, then remove $mydomain from the mydestination directive.  Problem solved.  Thanks for the help!